diff --git a/.dockerignore b/.dockerignore index 332da2e..b1417ea 100644 --- a/.dockerignore +++ b/.dockerignore @@ -9,7 +9,8 @@ .idea node_modules -dist +# 勿排除 dist:宿主机构建 Dockerfile / Dockerfile.k3s.runtime 需要 COPY dist/ +# Kaniko 多阶段会在镜像内重新 pnpm build,带上旧 dist 无妨 coverage *.log npm-debug.log* diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml index 0906f6e..900802f 100644 --- a/.gitea/workflows/deploy.yml +++ b/.gitea/workflows/deploy.yml @@ -1,8 +1,6 @@ # 复制到 itfx-front 仓库 .gitea/workflows/deploy.yml # push master → prod;push test → test -# 构建始终用 prod kubeconfig(Kaniko);仅 deploy 切集群 -# 前端镜像:test 分支须传 FRONT_BUILD_SCRIPT=build:test,否则会打进正式 API 域名 -# 构建变慢时:确认宿主机 ci-publish-front.sh 已给 Kaniko --cache=true(lock 不变时应跳过 pnpm install) +# 构建:runner 宿主 pnpm + docker(ci-publish-front.sh);仅 deploy 切集群 name: Build and Deploy Front on: diff --git a/Dockerfile b/Dockerfile index 0112129..f6cc94f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,6 @@ -# 本地/简易 Docker:仅静态 SPA。HTTPS 由外层网关(如 Traefik)终结。 -# 构建前先执行:pnpm build -FROM docker.m.daocloud.io/library/node:20-alpine -WORKDIR /app -RUN npm config set registry https://registry.npmmirror.com \ - && npm install -g serve@14.2.4 -COPY dist/ ./dist/ +# 本地/简易:先 pnpm build,再 docker build +# HTTPS 由外层网关(Traefik)终结 +FROM docker.m.daocloud.io/library/nginx:1.27-alpine +COPY dist/ /usr/share/nginx/html/ +COPY nginx-k3s.conf /etc/nginx/conf.d/default.conf EXPOSE 80 -CMD ["serve", "-s", "dist", "-l", "80"] diff --git a/Dockerfile.k3s b/Dockerfile.k3s index 97e3896..4b09171 100644 --- a/Dockerfile.k3s +++ b/Dockerfile.k3s @@ -1,43 +1,17 @@ -# k3s / Kaniko:静态 SPA(方案 A)。TLS 由 Traefik(websecure) + cert-manager 终结。 -# API 由浏览器按站点域名直连: -# test.ideship.com → api.test.ideship.com;其余 → api.ideship.com -# FRONT_BUILD_SCRIPT: -# prod 默认 build(.env.production → api.ideship.com) -# test 传 build:test(.env.ideship-test → api.test.ideship.com) -# 即使误用 production 构建,运行时也会按 hostname 纠正到测试 API。 -# -# 构建耗时提示(宿主机 ci-publish-front.sh): -# 务必给 Kaniko 开 --cache=true(及 cache-repo / cache-ttl), -# 否则每次都会全量 pnpm install + vite build(本地 vite alone 约 3~4 分钟)。 - -# ---------- 运行时 serve:与源码无关,Kaniko 有 cache 时几乎秒过 ---------- -FROM docker.m.daocloud.io/library/node:20-alpine AS serve-runtime -RUN npm config set registry https://registry.npmmirror.com \ - && npm install -g serve@14.2.4 - -# ---------- 前端构建 ---------- +# k3s / Kaniko 备用:多阶段构建。生产 CI 优先宿主 pnpm + Dockerfile.k3s.runtime +# TLS 由 Traefik(websecure) + cert-manager 终结;API 浏览器直连。 FROM docker.m.daocloud.io/library/node:20-alpine AS build WORKDIR /app ARG FRONT_BUILD_SCRIPT=build - -# corepack 启用内置 pnpm,避免每次 npm install -g RUN corepack enable \ && corepack prepare pnpm@9.15.9 --activate \ && pnpm config set registry https://registry.npmmirror.com - COPY package.json pnpm-lock.yaml ./ -# --ignore-scripts:跳过 gifsicle/optipng 等原生编译(需 autoreconf;vite 未启用 imagemin) -# 先只装依赖,lock 不变时可命中 Kaniko 层缓存(最大收益) RUN pnpm install --frozen-lockfile --ignore-scripts - COPY . . RUN pnpm run ${FRONT_BUILD_SCRIPT} -# ---------- 最终镜像:只拷 serve + dist ---------- -FROM docker.m.daocloud.io/library/node:20-alpine -WORKDIR /app -COPY --from=serve-runtime /usr/local/lib/node_modules/serve /usr/local/lib/node_modules/serve -COPY --from=serve-runtime /usr/local/bin/serve /usr/local/bin/serve -COPY --from=build /app/dist ./dist +FROM docker.m.daocloud.io/library/nginx:1.27-alpine +COPY --from=build /app/dist /usr/share/nginx/html/ +COPY nginx-k3s.conf /etc/nginx/conf.d/default.conf EXPOSE 80 -CMD ["serve", "-s", "dist", "-l", "80"] diff --git a/Dockerfile.k3s.runtime b/Dockerfile.k3s.runtime new file mode 100644 index 0000000..20b48af --- /dev/null +++ b/Dockerfile.k3s.runtime @@ -0,0 +1,5 @@ +# 宿主机构建 dist 后只打 nginx 静态层(CI:ci-publish-front.sh) +FROM docker.m.daocloud.io/library/nginx:1.27-alpine +COPY dist/ /usr/share/nginx/html/ +COPY nginx-k3s.conf /etc/nginx/conf.d/default.conf +EXPOSE 80 diff --git a/nginx-k3s.conf b/nginx-k3s.conf new file mode 100644 index 0000000..64837cf --- /dev/null +++ b/nginx-k3s.conf @@ -0,0 +1,68 @@ +# k3s 方案 A:仅静态 SPA。API 由浏览器按域名直连;TLS 由 Traefik 终结。 +server { + listen 80; + server_name _; + + gzip on; + gzip_vary on; + gzip_min_length 1024; + gzip_types text/plain text/css text/xml text/javascript application/javascript application/json application/xml image/svg+xml; + + root /usr/share/nginx/html; + index index.html; + + # 官网静态(若存在);否则回退 SPA + location = / { + try_files /site/index.html /index.html =404; + add_header Cache-Control "no-cache, no-store, must-revalidate"; + add_header Pragma "no-cache"; + add_header Expires "0"; + } + + location = /site { + return 301 /; + } + location = /site/ { + return 301 /; + } + location = /site/index.html { + return 301 /; + } + location ^~ /site/ { + try_files $uri =404; + expires 7d; + add_header Cache-Control "public"; + access_log off; + } + + location = /favicon.ico { + try_files /favicon.png /favicon.ico =404; + expires 7d; + add_header Cache-Control "public"; + access_log off; + } + + location = /index.html { + add_header Cache-Control "no-cache, no-store, must-revalidate"; + add_header Pragma "no-cache"; + add_header Expires "0"; + } + + # 微信域名校验文件 + location ~* ^/MP_verify_[A-Za-z0-9]+\.txt$ { + try_files $uri =404; + add_header Cache-Control "no-cache"; + } + + location ~* \.(?:js|css|woff2?|ttf|eot|svg|png|jpe?g|gif|webp|ico|map)$ { + try_files $uri =404; + expires 7d; + add_header Cache-Control "public"; + access_log off; + } + + # SPA 路由回退 + location / { + try_files $uri $uri/ /index.html; + } +} diff --git a/src/api/agent/analysis.ts b/src/api/agent/analysis.ts new file mode 100644 index 0000000..44c5af3 --- /dev/null +++ b/src/api/agent/analysis.ts @@ -0,0 +1,187 @@ +import { axiosInstance } from '@/api/rbac' +import { assertBusinessOk, omsUrl } from '@/api/oms/common' + +export type AgentAnalysisTimeField = 'payTime' | 'createTime' + +export interface AgentAnalysisQueryParams { + startTime: string + endTime: string + timeField?: AgentAnalysisTimeField + topN?: number +} + +export interface AgentAnalysisKpi { + orderCount: number + gmvPreDiscount: number + customerPaid: number + commissionAccrued: number + commissionEstimated: number + commissionPending: number + commissionPaid: number + commissionRate: number | null + newBindCount: number + convertedBindCount: number + conversionRate: number | null +} + +export interface AgentAnalysisGrowth { + orderCount: number | null + gmvPreDiscount: number | null + customerPaid: number | null + commissionAccrued: number | null + commissionPending: number | null + commissionPaid: number | null + commissionRate: number | null + newBindCount: number | null + conversionRate: number | null +} + +export interface AgentAnalysisTrendPoint { + date: string + orderCount: number + commissionAccrued: number + newBindCount: number +} + +export interface AgentAnalysisOverview { + kpis: AgentAnalysisKpi + previousKpis: AgentAnalysisKpi + growth: AgentAnalysisGrowth + trend: AgentAnalysisTrendPoint[] +} + +export interface AgentAnalysisRankItem { + agentId: number + agentCode: string + agentName: string + orderCount: number + gmvPreDiscount: number + commissionAccrued: number + commissionRate: number | null + newBindCount: number + conversionRate: number | null + commissionPending: number +} + +function unwrapData(body: any): T { + assertBusinessOk(body) + return (body?.data ?? body?.Data ?? body) as T +} + +function toNullableNumber(value: unknown): number | null { + if (value == null || value === '') return null + const n = Number(value) + return Number.isFinite(n) ? n : null +} + +function normalizeKpi(raw: any): AgentAnalysisKpi { + return { + orderCount: Number(raw?.orderCount ?? raw?.OrderCount ?? 0), + gmvPreDiscount: Number(raw?.gmvPreDiscount ?? raw?.GmvPreDiscount ?? 0), + customerPaid: Number(raw?.customerPaid ?? raw?.CustomerPaid ?? 0), + commissionAccrued: Number(raw?.commissionAccrued ?? raw?.CommissionAccrued ?? 0), + commissionEstimated: Number(raw?.commissionEstimated ?? raw?.CommissionEstimated ?? 0), + commissionPending: Number(raw?.commissionPending ?? raw?.CommissionPending ?? 0), + commissionPaid: Number(raw?.commissionPaid ?? raw?.CommissionPaid ?? 0), + commissionRate: toNullableNumber(raw?.commissionRate ?? raw?.CommissionRate), + newBindCount: Number(raw?.newBindCount ?? raw?.NewBindCount ?? 0), + convertedBindCount: Number(raw?.convertedBindCount ?? raw?.ConvertedBindCount ?? 0), + conversionRate: toNullableNumber(raw?.conversionRate ?? raw?.ConversionRate), + } +} + +function normalizeGrowth(raw: any): AgentAnalysisGrowth { + return { + orderCount: toNullableNumber(raw?.orderCount ?? raw?.OrderCount), + gmvPreDiscount: toNullableNumber(raw?.gmvPreDiscount ?? raw?.GmvPreDiscount), + customerPaid: toNullableNumber(raw?.customerPaid ?? raw?.CustomerPaid), + commissionAccrued: toNullableNumber(raw?.commissionAccrued ?? raw?.CommissionAccrued), + commissionPending: toNullableNumber(raw?.commissionPending ?? raw?.CommissionPending), + commissionPaid: toNullableNumber(raw?.commissionPaid ?? raw?.CommissionPaid), + commissionRate: toNullableNumber(raw?.commissionRate ?? raw?.CommissionRate), + newBindCount: toNullableNumber(raw?.newBindCount ?? raw?.NewBindCount), + conversionRate: toNullableNumber(raw?.conversionRate ?? raw?.ConversionRate), + } +} + +function buildParams(params: AgentAnalysisQueryParams) { + return { + startTime: params.startTime, + endTime: params.endTime, + timeField: params.timeField || 'payTime', + topN: params.topN, + } +} + +/** GET /agent/admin/analysis/overview */ +export async function getAgentAnalysisOverview(params: AgentAnalysisQueryParams) { + const res = await axiosInstance.get(omsUrl('/agent/admin/analysis/overview'), { + params: buildParams(params), + }) + const raw = unwrapData(res.data) + return { + kpis: normalizeKpi(raw?.kpis ?? raw?.Kpis), + previousKpis: normalizeKpi(raw?.previousKpis ?? raw?.PreviousKpis), + growth: normalizeGrowth(raw?.growth ?? raw?.Growth), + trend: (raw?.trend ?? raw?.Trend ?? []).map((item: any) => ({ + date: String(item?.date ?? item?.Date ?? ''), + orderCount: Number(item?.orderCount ?? item?.OrderCount ?? 0), + commissionAccrued: Number(item?.commissionAccrued ?? item?.CommissionAccrued ?? 0), + newBindCount: Number(item?.newBindCount ?? item?.NewBindCount ?? 0), + })), + } satisfies AgentAnalysisOverview +} + +/** GET /agent/admin/analysis/ranking */ +export async function getAgentAnalysisRanking(params: AgentAnalysisQueryParams) { + const res = await axiosInstance.get(omsUrl('/agent/admin/analysis/ranking'), { + params: buildParams(params), + }) + const raw = unwrapData(res.data) + const agents = (raw?.agents ?? raw?.Agents ?? []).map((item: any) => ({ + agentId: Number(item?.agentId ?? item?.AgentId ?? 0), + agentCode: String(item?.agentCode ?? item?.AgentCode ?? ''), + agentName: String(item?.agentName ?? item?.AgentName ?? ''), + orderCount: Number(item?.orderCount ?? item?.OrderCount ?? 0), + gmvPreDiscount: Number(item?.gmvPreDiscount ?? item?.GmvPreDiscount ?? 0), + commissionAccrued: Number(item?.commissionAccrued ?? item?.CommissionAccrued ?? 0), + commissionRate: toNullableNumber(item?.commissionRate ?? item?.CommissionRate), + newBindCount: Number(item?.newBindCount ?? item?.NewBindCount ?? 0), + conversionRate: toNullableNumber(item?.conversionRate ?? item?.ConversionRate), + commissionPending: Number(item?.commissionPending ?? item?.CommissionPending ?? 0), + })) as AgentAnalysisRankItem[] + return { agents } +} + +/** GET /agent/admin/analysis/ranking/export */ +export async function exportAgentAnalysisRanking(params: AgentAnalysisQueryParams) { + const res = await axiosInstance.get(omsUrl('/agent/admin/analysis/ranking/export'), { + params: buildParams(params), + responseType: 'blob', + }) + const blob = res.data as Blob + const ct = (res.headers['content-type'] || '').toString() + if (ct.includes('application/json')) { + const text = await blob.text() + try { + const json = JSON.parse(text) + throw new Error(json.msg ?? json.message ?? json.Message ?? '导出失败') + } catch (e: any) { + if (e?.message && e.message !== '导出失败') throw e + throw new Error(text || '导出失败') + } + } + const disposition = (res.headers['content-disposition'] || '').toString() + let fileName = `agent-analysis-${new Date().toISOString().slice(0, 10)}.xlsx` + const match = disposition.match(/filename\*?=(?:UTF-8'')?["']?([^"';]+)/i) + if (match?.[1]) fileName = decodeURIComponent(match[1].trim()) + const url = URL.createObjectURL(blob) + const a = document.createElement('a') + a.href = url + a.download = fileName.endsWith('.xlsx') ? fileName : `${fileName}.xlsx` + a.style.display = 'none' + document.body.appendChild(a) + a.click() + document.body.removeChild(a) + URL.revokeObjectURL(url) +} diff --git a/src/api/finance/receivablePayable.ts b/src/api/finance/receivablePayable.ts index 260f13b..535e720 100644 --- a/src/api/finance/receivablePayable.ts +++ b/src/api/finance/receivablePayable.ts @@ -8,6 +8,9 @@ export interface ReceivablePayableFilterParams { chargingStage?: string customerId?: number customerCode?: string + productCode?: string + channelCode?: string + agentId?: number effectiveStageOnly?: boolean timeField?: 'createTime' | 'receiveTime' | 'shipTime' | 'payTime' isPaid?: number @@ -26,12 +29,16 @@ export interface ReceivablePayableRow { clientNo?: string trackNo?: string customerCode?: string + /** 下单时代理快照 Order.AgentId */ + agentId?: number | null + agentName?: string | null orderStatus: string orderStatusName?: string isPaid: number payTime?: string receiveTime?: string shipTime?: string + createTime?: string productCode?: string channelCode?: string consigneeCountryName?: string @@ -69,6 +76,9 @@ function buildFilterQueryParams(params: ReceivablePayableFilterParams) { chargingStage: params.chargingStage && params.chargingStage !== 'all' ? params.chargingStage : undefined, customerId: params.customerId || undefined, customerCode: params.customerCode || undefined, + productCode: params.productCode || undefined, + channelCode: params.channelCode || undefined, + agentId: params.agentId || undefined, effectiveStageOnly: params.effectiveStageOnly ? true : undefined, timeField: params.timeField || undefined, isPaid: params.isPaid === 0 || params.isPaid === 1 ? params.isPaid : undefined, @@ -87,6 +97,41 @@ function mapSummaryItem(item: any): ReceivablePayableSummaryItem { } } +function mapReceivablePayableRow(item: any): ReceivablePayableRow { + const agentIdRaw = item.agentId ?? item.AgentId + const agentIdNum = Number(agentIdRaw) + return { + orderId: item.orderId ?? item.OrderId, + serviceNo: item.serviceNo ?? item.ServiceNo ?? '', + clientNo: item.clientNo ?? item.ClientNo, + trackNo: item.trackNo ?? item.TrackNo, + customerCode: item.customerCode ?? item.CustomerCode, + agentId: Number.isFinite(agentIdNum) && agentIdNum > 0 ? agentIdNum : null, + agentName: item.agentName ?? item.AgentName ?? null, + orderStatus: item.orderStatus ?? item.OrderStatus ?? '', + orderStatusName: item.orderStatusName ?? item.OrderStatusName, + isPaid: Number(item.isPaid ?? item.IsPaid ?? 0), + payTime: item.payTime ?? item.PayTime, + receiveTime: item.receiveTime ?? item.ReceiveTime, + shipTime: item.shipTime ?? item.ShipTime, + createTime: item.createTime ?? item.CreateTime, + productCode: item.productCode ?? item.ProductCode, + channelCode: item.channelCode ?? item.ChannelCode, + consigneeCountryName: item.consigneeCountryName ?? item.ConsigneeCountryName, + feeType: item.feeType ?? item.FeeType ?? '', + feeTypeName: item.feeTypeName ?? item.FeeTypeName, + costItem: item.costItem ?? item.CostItem ?? '', + costItemName: item.costItemName ?? item.CostItemName, + amount: Number(item.amount ?? item.Amount ?? 0), + currency: item.currency ?? item.Currency ?? 'CNY', + downstreamProvider: item.downstreamProvider ?? item.DownstreamProvider, + priceNo: item.priceNo ?? item.PriceNo, + priceEffectiveTime: item.priceEffectiveTime ?? item.PriceEffectiveTime, + chargingStage: item.chargingStage ?? item.ChargingStage, + chargingStageName: item.chargingStageName ?? item.ChargingStageName, + } +} + export async function getReceivablePayableList(params: ReceivablePayableListParams) { const res = await axiosInstance.get(omsUrl('/finance/receivable-payable/list'), { params: { @@ -95,7 +140,11 @@ export async function getReceivablePayableList(params: ReceivablePayableListPara ...buildFilterQueryParams(params), }, }) - return parseListPayload(res.data) + const payload = parseListPayload(res.data) + return { + items: (payload.items || []).map(mapReceivablePayableRow), + total: payload.total, + } } export async function getReceivablePayableSummary( diff --git a/src/api/marketing/analysis.ts b/src/api/marketing/analysis.ts new file mode 100644 index 0000000..0e4009d --- /dev/null +++ b/src/api/marketing/analysis.ts @@ -0,0 +1,323 @@ +import { axiosInstance } from '@/api/rbac' +import { assertBusinessOk, omsUrl } from '@/api/oms/common' + +export type MarketingAnalysisTimeField = 'payTime' | 'createTime' + +export interface MarketingAnalysisQueryParams { + startTime: string + endTime: string + timeField?: MarketingAnalysisTimeField + topN?: number +} + +export interface MarketingAnalysisKpi { + gmvPreDiscount: number + couponDiscount: number + levelDiscount: number + marketingCost: number + discountRate: number | null + customerPaid: number + orderCount: number + couponOrderCount: number + couponOrderRate: number | null +} + +export interface MarketingAnalysisGrowth { + gmvPreDiscount: number | null + marketingCost: number | null + discountRate: number | null + customerPaid: number | null + orderCount: number | null + couponOrderCount: number | null + couponOrderRate: number | null +} + +export interface MarketingAnalysisTrendPoint { + date: string + gmvPreDiscount: number + marketingCost: number + customerPaid: number +} + +export interface MarketingAnalysisDiscountMix { + couponDiscount: number + levelDiscount: number +} + +export interface MarketingAnalysisOverview { + kpis: MarketingAnalysisKpi + previousKpis: MarketingAnalysisKpi + growth: MarketingAnalysisGrowth + trend: MarketingAnalysisTrendPoint[] + discountMix: MarketingAnalysisDiscountMix +} + +export interface MarketingCouponFunnel { + issued: number + used: number + expired: number + redemptionRate: number | null +} + +export interface MarketingCouponTemplateRank { + templateId: number + templateCode: string + templateName: string + grantChannel: string + issued: number + used: number + expired: number + redemptionRate: number | null + orderCount: number + discountAmount: number + gmvPreDiscount: number + discountToGmvRate: number | null +} + +export interface MarketingAnalysisCoupons { + funnel: MarketingCouponFunnel + availableLiability: number + templates: MarketingCouponTemplateRank[] +} + +function unwrapData(body: any): T { + assertBusinessOk(body) + return (body?.data ?? body?.Data ?? body) as T +} + +function normalizeKpi(raw: any): MarketingAnalysisKpi { + return { + gmvPreDiscount: Number(raw?.gmvPreDiscount ?? raw?.GmvPreDiscount ?? 0), + couponDiscount: Number(raw?.couponDiscount ?? raw?.CouponDiscount ?? 0), + levelDiscount: Number(raw?.levelDiscount ?? raw?.LevelDiscount ?? 0), + marketingCost: Number(raw?.marketingCost ?? raw?.MarketingCost ?? 0), + discountRate: toNullableNumber(raw?.discountRate ?? raw?.DiscountRate), + customerPaid: Number(raw?.customerPaid ?? raw?.CustomerPaid ?? 0), + orderCount: Number(raw?.orderCount ?? raw?.OrderCount ?? 0), + couponOrderCount: Number(raw?.couponOrderCount ?? raw?.CouponOrderCount ?? 0), + couponOrderRate: toNullableNumber(raw?.couponOrderRate ?? raw?.CouponOrderRate), + } +} + +function normalizeGrowth(raw: any): MarketingAnalysisGrowth { + return { + gmvPreDiscount: toNullableNumber(raw?.gmvPreDiscount ?? raw?.GmvPreDiscount), + marketingCost: toNullableNumber(raw?.marketingCost ?? raw?.MarketingCost), + discountRate: toNullableNumber(raw?.discountRate ?? raw?.DiscountRate), + customerPaid: toNullableNumber(raw?.customerPaid ?? raw?.CustomerPaid), + orderCount: toNullableNumber(raw?.orderCount ?? raw?.OrderCount), + couponOrderCount: toNullableNumber(raw?.couponOrderCount ?? raw?.CouponOrderCount), + couponOrderRate: toNullableNumber(raw?.couponOrderRate ?? raw?.CouponOrderRate), + } +} + +function toNullableNumber(value: unknown): number | null { + if (value == null || value === '') return null + const n = Number(value) + return Number.isFinite(n) ? n : null +} + +function buildParams(params: MarketingAnalysisQueryParams) { + return { + startTime: params.startTime, + endTime: params.endTime, + timeField: params.timeField || 'payTime', + topN: params.topN, + } +} + +/** GET /marketing/analysis/overview */ +export async function getMarketingAnalysisOverview(params: MarketingAnalysisQueryParams) { + const res = await axiosInstance.get(omsUrl('/marketing/analysis/overview'), { + params: buildParams(params), + }) + const raw = unwrapData(res.data) + return { + kpis: normalizeKpi(raw?.kpis ?? raw?.Kpis), + previousKpis: normalizeKpi(raw?.previousKpis ?? raw?.PreviousKpis), + growth: normalizeGrowth(raw?.growth ?? raw?.Growth), + trend: (raw?.trend ?? raw?.Trend ?? []).map((item: any) => ({ + date: String(item?.date ?? item?.Date ?? ''), + gmvPreDiscount: Number(item?.gmvPreDiscount ?? item?.GmvPreDiscount ?? 0), + marketingCost: Number(item?.marketingCost ?? item?.MarketingCost ?? 0), + customerPaid: Number(item?.customerPaid ?? item?.CustomerPaid ?? 0), + })), + discountMix: { + couponDiscount: Number( + raw?.discountMix?.couponDiscount ?? + raw?.DiscountMix?.CouponDiscount ?? + raw?.discountMix?.CouponDiscount ?? + 0, + ), + levelDiscount: Number( + raw?.discountMix?.levelDiscount ?? + raw?.DiscountMix?.LevelDiscount ?? + raw?.discountMix?.LevelDiscount ?? + 0, + ), + }, + } satisfies MarketingAnalysisOverview +} + +/** GET /marketing/analysis/coupons */ +export async function getMarketingAnalysisCoupons(params: MarketingAnalysisQueryParams) { + const res = await axiosInstance.get(omsUrl('/marketing/analysis/coupons'), { + params: buildParams(params), + }) + const raw = unwrapData(res.data) + const funnelRaw = raw?.funnel ?? raw?.Funnel ?? {} + return { + funnel: { + issued: Number(funnelRaw?.issued ?? funnelRaw?.Issued ?? 0), + used: Number(funnelRaw?.used ?? funnelRaw?.Used ?? 0), + expired: Number(funnelRaw?.expired ?? funnelRaw?.Expired ?? 0), + redemptionRate: toNullableNumber(funnelRaw?.redemptionRate ?? funnelRaw?.RedemptionRate), + }, + availableLiability: Number(raw?.availableLiability ?? raw?.AvailableLiability ?? 0), + templates: (raw?.templates ?? raw?.Templates ?? []).map((item: any) => ({ + templateId: Number(item?.templateId ?? item?.TemplateId ?? 0), + templateCode: String(item?.templateCode ?? item?.TemplateCode ?? ''), + templateName: String(item?.templateName ?? item?.TemplateName ?? ''), + grantChannel: String(item?.grantChannel ?? item?.GrantChannel ?? ''), + issued: Number(item?.issued ?? item?.Issued ?? 0), + used: Number(item?.used ?? item?.Used ?? 0), + expired: Number(item?.expired ?? item?.Expired ?? 0), + redemptionRate: toNullableNumber(item?.redemptionRate ?? item?.RedemptionRate), + orderCount: Number(item?.orderCount ?? item?.OrderCount ?? 0), + discountAmount: Number(item?.discountAmount ?? item?.DiscountAmount ?? 0), + gmvPreDiscount: Number(item?.gmvPreDiscount ?? item?.GmvPreDiscount ?? 0), + discountToGmvRate: toNullableNumber(item?.discountToGmvRate ?? item?.DiscountToGmvRate), + })), + } satisfies MarketingAnalysisCoupons +} + +export interface MarketingPointsKpi { + earnPoints: number + earnCount: number + clawbackPoints: number + clawbackCount: number + adjustPoints: number + adjustCount: number + largeAdjustCount: number + consumePoints: number +} + +export interface MarketingPointsGrowth { + earnPoints: number | null + clawbackPoints: number | null + adjustPoints: number | null + adjustCount: number | null + largeAdjustCount: number | null +} + +export interface MarketingPointsTrendPoint { + date: string + earnPoints: number + clawbackPoints: number + adjustPoints: number +} + +export interface MarketingPointsLiability { + accountWithPoints: number + availablePointsTotal: number + totalPointsSum: number + avgAvailablePoints: number | null +} + +export interface MarketingAnalysisPoints { + kpis: MarketingPointsKpi + previousKpis: MarketingPointsKpi + growth: MarketingPointsGrowth + trend: MarketingPointsTrendPoint[] + liability: MarketingPointsLiability +} + +function normalizePointsKpi(raw: any): MarketingPointsKpi { + return { + earnPoints: Number(raw?.earnPoints ?? raw?.EarnPoints ?? 0), + earnCount: Number(raw?.earnCount ?? raw?.EarnCount ?? 0), + clawbackPoints: Number(raw?.clawbackPoints ?? raw?.ClawbackPoints ?? 0), + clawbackCount: Number(raw?.clawbackCount ?? raw?.ClawbackCount ?? 0), + adjustPoints: Number(raw?.adjustPoints ?? raw?.AdjustPoints ?? 0), + adjustCount: Number(raw?.adjustCount ?? raw?.AdjustCount ?? 0), + largeAdjustCount: Number(raw?.largeAdjustCount ?? raw?.LargeAdjustCount ?? 0), + consumePoints: Number(raw?.consumePoints ?? raw?.ConsumePoints ?? 0), + } +} + +function normalizePointsGrowth(raw: any): MarketingPointsGrowth { + return { + earnPoints: toNullableNumber(raw?.earnPoints ?? raw?.EarnPoints), + clawbackPoints: toNullableNumber(raw?.clawbackPoints ?? raw?.ClawbackPoints), + adjustPoints: toNullableNumber(raw?.adjustPoints ?? raw?.AdjustPoints), + adjustCount: toNullableNumber(raw?.adjustCount ?? raw?.AdjustCount), + largeAdjustCount: toNullableNumber(raw?.largeAdjustCount ?? raw?.LargeAdjustCount), + } +} + +/** GET /marketing/analysis/points */ +export async function getMarketingAnalysisPoints(params: MarketingAnalysisQueryParams) { + const res = await axiosInstance.get(omsUrl('/marketing/analysis/points'), { + params: buildParams(params), + }) + const raw = unwrapData(res.data) + const liabilityRaw = raw?.liability ?? raw?.Liability ?? {} + return { + kpis: normalizePointsKpi(raw?.kpis ?? raw?.Kpis), + previousKpis: normalizePointsKpi(raw?.previousKpis ?? raw?.PreviousKpis), + growth: normalizePointsGrowth(raw?.growth ?? raw?.Growth), + trend: (raw?.trend ?? raw?.Trend ?? []).map((item: any) => ({ + date: String(item?.date ?? item?.Date ?? ''), + earnPoints: Number(item?.earnPoints ?? item?.EarnPoints ?? 0), + clawbackPoints: Number(item?.clawbackPoints ?? item?.ClawbackPoints ?? 0), + adjustPoints: Number(item?.adjustPoints ?? item?.AdjustPoints ?? 0), + })), + liability: { + accountWithPoints: Number( + liabilityRaw?.accountWithPoints ?? liabilityRaw?.AccountWithPoints ?? 0, + ), + availablePointsTotal: Number( + liabilityRaw?.availablePointsTotal ?? liabilityRaw?.AvailablePointsTotal ?? 0, + ), + totalPointsSum: Number(liabilityRaw?.totalPointsSum ?? liabilityRaw?.TotalPointsSum ?? 0), + avgAvailablePoints: toNullableNumber( + liabilityRaw?.avgAvailablePoints ?? liabilityRaw?.AvgAvailablePoints, + ), + }, + } satisfies MarketingAnalysisPoints +} + +/** GET /marketing/analysis/coupons/export */ +export async function exportMarketingAnalysisCoupons(params: MarketingAnalysisQueryParams) { + const res = await axiosInstance.get(omsUrl('/marketing/analysis/coupons/export'), { + params: buildParams(params), + responseType: 'blob', + }) + const blob = res.data as Blob + const ct = (res.headers['content-type'] || '').toString() + if (ct.includes('application/json')) { + const text = await blob.text() + try { + const json = JSON.parse(text) + throw new Error(json.msg ?? json.message ?? json.Message ?? '导出失败') + } catch (e: any) { + if (e?.message && e.message !== '导出失败') throw e + throw new Error(text || '导出失败') + } + } + const disposition = (res.headers['content-disposition'] || '').toString() + let fileName = `marketing-coupons-${new Date().toISOString().slice(0, 10)}.xlsx` + const match = disposition.match(/filename\*?=(?:UTF-8'')?["']?([^"';]+)/i) + if (match?.[1]) { + fileName = decodeURIComponent(match[1].trim()) + } + const url = URL.createObjectURL(blob) + const a = document.createElement('a') + a.href = url + a.download = fileName.endsWith('.xlsx') ? fileName : `${fileName}.xlsx` + a.style.display = 'none' + document.body.appendChild(a) + a.click() + document.body.removeChild(a) + URL.revokeObjectURL(url) +} diff --git a/src/api/mcp/index.ts b/src/api/mcp/index.ts index b3c72c4..189632f 100644 --- a/src/api/mcp/index.ts +++ b/src/api/mcp/index.ts @@ -111,6 +111,8 @@ export async function chatAiAgent(payload: { messages: { role: string; content: string }[]; toolKeys?: string[]; maxToolRounds?: number; + /** customer=客户三工具;ops=运营排障且不挂客户 MCP 工具 */ + audience?: 'customer' | 'ops'; }): Promise { // 走 /ai/agent/chat:开发 Vite 反代 /ai/;生产浏览器直连 api.* 域名 // 后端另注册 /mcp/agent/chat,部署后可再切 diff --git a/src/assets/icons/h5/ops-bag.svg b/src/assets/icons/h5/ops-bag.svg new file mode 100644 index 0000000..b4a8f21 --- /dev/null +++ b/src/assets/icons/h5/ops-bag.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/assets/icons/h5/ops-fulfill.svg b/src/assets/icons/h5/ops-fulfill.svg new file mode 100644 index 0000000..731ce44 --- /dev/null +++ b/src/assets/icons/h5/ops-fulfill.svg @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/src/assets/icons/h5/ops-inbound.svg b/src/assets/icons/h5/ops-inbound.svg new file mode 100644 index 0000000..61979dd --- /dev/null +++ b/src/assets/icons/h5/ops-inbound.svg @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/src/assets/icons/h5/ops-master.svg b/src/assets/icons/h5/ops-master.svg new file mode 100644 index 0000000..7f1a45e --- /dev/null +++ b/src/assets/icons/h5/ops-master.svg @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/assets/icons/h5/ops-outbound.svg b/src/assets/icons/h5/ops-outbound.svg new file mode 100644 index 0000000..c7e7bec --- /dev/null +++ b/src/assets/icons/h5/ops-outbound.svg @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/src/assets/icons/h5/ops-parcel.svg b/src/assets/icons/h5/ops-parcel.svg new file mode 100644 index 0000000..60c0393 --- /dev/null +++ b/src/assets/icons/h5/ops-parcel.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/assets/images/edi-live.webp b/src/assets/images/edi-live.webp new file mode 100644 index 0000000..a94b0b3 Binary files /dev/null and b/src/assets/images/edi-live.webp differ diff --git a/src/assets/images/edi.png b/src/assets/images/edi.png new file mode 100644 index 0000000..98108c1 Binary files /dev/null and b/src/assets/images/edi.png differ diff --git a/src/assets/images/nana.png b/src/assets/images/nana.png deleted file mode 100644 index b36c9cc..0000000 Binary files a/src/assets/images/nana.png and /dev/null differ diff --git a/src/auto-imports.d.ts b/src/auto-imports.d.ts index b57132f..3bf4bbc 100644 --- a/src/auto-imports.d.ts +++ b/src/auto-imports.d.ts @@ -230,7 +230,7 @@ declare global { const useMouseInElement: typeof import('@vueuse/core')['useMouseInElement'] const useMousePressed: typeof import('@vueuse/core')['useMousePressed'] const useMutationObserver: typeof import('@vueuse/core')['useMutationObserver'] - const useNanaBatchPanel: typeof import('./composables/useNanaBatchPanel')['useNanaBatchPanel'] + const useEdiBatchPanel: typeof import('./composables/useEdiBatchPanel')['useEdiBatchPanel'] const useNavigatorLanguage: typeof import('@vueuse/core')['useNavigatorLanguage'] const useNetwork: typeof import('@vueuse/core')['useNetwork'] const useNow: typeof import('@vueuse/core')['useNow'] @@ -345,8 +345,8 @@ declare global { export type { WaybillSource, WaybillContext } from './composables/useAskAdvisor' import('./composables/useAskAdvisor') // @ts-ignore - export type { NanaBatchOpenOptions } from './composables/useNanaBatchPanel' - import('./composables/useNanaBatchPanel') + export type { EdiBatchOpenOptions } from './composables/useEdiBatchPanel' + import('./composables/useEdiBatchPanel') // @ts-ignore export type { ScanFeedbackType } from './composables/useOperationScanFeedback' import('./composables/useOperationScanFeedback') @@ -587,7 +587,7 @@ declare module 'vue' { readonly useMouseInElement: UnwrapRef readonly useMousePressed: UnwrapRef readonly useMutationObserver: UnwrapRef - readonly useNanaBatchPanel: UnwrapRef + readonly useEdiBatchPanel: UnwrapRef readonly useNavigatorLanguage: UnwrapRef readonly useNetwork: UnwrapRef readonly useNow: UnwrapRef diff --git a/src/components.d.ts b/src/components.d.ts index 03c28ae..e704367 100644 --- a/src/components.d.ts +++ b/src/components.d.ts @@ -10,7 +10,7 @@ declare module 'vue' { export interface GlobalComponents { ActiveFilterBar: typeof import('./components/HandsontablePro/ActiveFilterBar.vue')['default'] AgentSideRail: typeof import('./components/agent-side-rail/index.vue')['default'] - AiAdvisorShell: typeof import('./components/NanaAssistant/AiAdvisorShell.vue')['default'] + AiAdvisorShell: typeof import('./components/EdiAssistant/AiAdvisorShell.vue')['default'] ApiTest: typeof import('./components/ApiTest/index.vue')['default'] ApprovalDetailDrawer: typeof import('./components/ApprovalDetailDrawer/index.vue')['default'] BasicLayoutLeftRight: typeof import('./components/BasicLayoutLeftRight/index.vue')['default'] @@ -24,6 +24,11 @@ declare module 'vue' { CustomLeftMenu: typeof import('./components/CustomLeftMenu/index.vue')['default'] CustomList: typeof import('./components/CustomList/index.vue')['default'] DrawerPro: typeof import('./components/DrawerPro/index.vue')['default'] + EdiAssistant: typeof import('./components/EdiAssistant/index.vue')['default'] + EdiAvatar: typeof import('./components/EdiAssistant/EdiAvatar.vue')['default'] + EdiBatchJobsDrawer: typeof import('./components/EdiAssistant/EdiBatchJobsDrawer.vue')['default'] + EdiChatDialog: typeof import('./components/EdiAssistant/EdiChatDialog.vue')['default'] + EdiComposer: typeof import('./components/EdiAssistant/EdiComposer.vue')['default'] EmployeeProfileFields: typeof import('./components/EmployeeProfileFields/index.vue')['default'] ExcelFileIcon: typeof import('./components/icons/ExcelFileIcon.vue')['default'] Footer: typeof import('./components/footer/index.vue')['default'] @@ -44,11 +49,6 @@ declare module 'vue' { MenuIconPicker: typeof import('./components/MenuIconPicker/index.vue')['default'] ModalForm: typeof import('./components/ModalForm/index.vue')['default'] ModalPro: typeof import('./components/ModalPro/index.vue')['default'] - NanaAssistant: typeof import('./components/NanaAssistant/index.vue')['default'] - NanaAvatar: typeof import('./components/NanaAssistant/NanaAvatar.vue')['default'] - NanaBatchJobsDrawer: typeof import('./components/NanaAssistant/NanaBatchJobsDrawer.vue')['default'] - NanaChatDialog: typeof import('./components/NanaAssistant/NanaChatDialog.vue')['default'] - NanaComposer: typeof import('./components/NanaAssistant/NanaComposer.vue')['default'] OrderPrintModal: typeof import('./components/PrintTemplate/OrderPrintModal.vue')['default'] PaginationPro: typeof import('./components/PaginationPro/index.vue')['default'] PrintOptionsForm: typeof import('./components/PrintTemplate/PrintOptionsForm.vue')['default'] diff --git a/src/components/NanaAssistant/AiAdvisorShell.vue b/src/components/EdiAssistant/AiAdvisorShell.vue similarity index 67% rename from src/components/NanaAssistant/AiAdvisorShell.vue rename to src/components/EdiAssistant/AiAdvisorShell.vue index 160de40..469a016 100644 --- a/src/components/NanaAssistant/AiAdvisorShell.vue +++ b/src/components/EdiAssistant/AiAdvisorShell.vue @@ -1,39 +1,52 @@
-

{{ t('nanaAssistant.noAdvisor') }}

+

{{ t('ediAssistant.noAdvisor') }}

@@ -297,6 +439,7 @@ import { useI18n } from 'vue-i18n'; import { Message } from '@arco-design/web-vue'; import { IconClockCircle, + IconClose, IconCustomerService, IconDelete, IconFile, @@ -328,6 +471,7 @@ import { parseWaybillContextFromQuery, type WaybillContext, } from '@/composables/useAskAdvisor'; +import { useEdiAdvisorPanel } from '@/composables/useEdiAdvisorPanel'; import IconTabCalculator from '@/assets/icons/h5/tab-calculator.svg'; import IconTabPackage from '@/assets/icons/h5/tab-package.svg'; import { @@ -338,19 +482,40 @@ import { inferCapabilityFromText, type McpCapabilityId, } from '@/composables/assistantMcpGuide'; +import { + buildOpsGuideContext, + listOpsGuideModules, +} from '@/composables/opsGuideKnowledge'; +import { useRbacUserStore } from '@/store/modules/rbac-user'; import { isMobileUserAgent, isWeChatBrowser } from '@/utils/device'; import { openWecomKf } from '@/utils/wecomKf'; import { resolveTextModelId } from '@/views/system/aiAssistant/providerCatalog'; -import NanaAvatar from './NanaAvatar.vue'; -import NanaChatDialog from './NanaChatDialog.vue'; -import NanaComposer from './NanaComposer.vue'; +import EdiAvatar from './EdiAvatar.vue'; +import EdiChatDialog from './EdiChatDialog.vue'; +import EdiComposer from './EdiComposer.vue'; import logoImg from '@/assets/logo2.png'; -/** @deprecated 圆钮发送已默认开启,保留 prop 兼容旧调用方 */ -defineProps<{ - roundSend?: boolean; +const props = withDefaults( + defineProps<{ + /** @deprecated 圆钮发送已默认开启,保留 prop 兼容旧调用方 */ + roundSend?: boolean; + /** page=路由页;float=FAB 旁浮窗 */ + mode?: 'page' | 'float'; + }>(), + { + roundSend: true, + mode: 'page', + }, +); + +const emit = defineEmits<{ + close: []; + /** 浮窗顶栏拖动 */ + 'float-drag-start': [event: PointerEvent]; }>(); +const mode = computed(() => props.mode); + type QuickTagDef = { id: string; icon: typeof IconStorage; @@ -393,6 +558,12 @@ const WECHAT_QR_PLACEHOLDER_SVG = `data:image/svg+xml;charset=utf-8,${encodeURIC const { t, locale } = useI18n(); const router = useRouter(); const route = useRoute(); +const rbacUserStore = useRbacUserStore(); + +/** 运营端排障:非客户/代理门户;关掉客户 MCP 三工具 */ +const isOpsAudience = computed( + () => !rbacUserStore.isCustomerPortal() && !rbacUserStore.isAgentPortal(), +); const historyOpen = ref(false); const historySearch = ref(''); @@ -422,7 +593,7 @@ function mcpCardIcon(id: McpCapabilityId) { const activeThreadId = ref(null); const messages = ref([]); const mainScrollRef = ref(); -const composerRef = ref | null>(null); +const composerRef = ref | null>(null); const advisorLoading = ref(false); const advisorLoaded = ref(false); @@ -430,31 +601,31 @@ const advisor = ref({}); const advisorQrLoadFailed = ref(false); const quickTagDefs: QuickTagDef[] = [ - { id: 'small', icon: IconStorage, labelKey: 'nanaAssistant.quickSmall', replyKey: 'nanaAssistant.replySmall' }, - { id: 'price', icon: IconPublic, labelKey: 'nanaAssistant.quickPrice', replyKey: 'nanaAssistant.replyPrice' }, + { id: 'small', icon: IconStorage, labelKey: 'ediAssistant.quickSmall', replyKey: 'ediAssistant.replySmall' }, + { id: 'price', icon: IconPublic, labelKey: 'ediAssistant.quickPrice', replyKey: 'ediAssistant.replyPrice' }, { id: 'quote-speed', icon: IconClockCircle, - labelKey: 'nanaAssistant.quickQuoteSpeed', - replyKey: 'nanaAssistant.replyQuoteSpeed', + labelKey: 'ediAssistant.quickQuoteSpeed', + replyKey: 'ediAssistant.replyQuoteSpeed', }, - { id: 'track', icon: IconLocation, labelKey: 'nanaAssistant.quickTrack', track: true }, + { id: 'track', icon: IconLocation, labelKey: 'ediAssistant.quickTrack', track: true }, { id: 'visibility', icon: IconWifi, - labelKey: 'nanaAssistant.quickVisibility', - replyKey: 'nanaAssistant.replyVisibility', + labelKey: 'ediAssistant.quickVisibility', + replyKey: 'ediAssistant.replyVisibility', }, { id: 'after-sales', icon: IconCustomerService, - labelKey: 'nanaAssistant.quickAfterSales', - replyKey: 'nanaAssistant.replyAfterSales', + labelKey: 'ediAssistant.quickAfterSales', + replyKey: 'ediAssistant.replyAfterSales', }, { id: 'human', icon: IconUser, - labelKey: 'nanaAssistant.quickHuman', + labelKey: 'ediAssistant.quickHuman', human: true, iconSrc: logoImg, }, @@ -491,17 +662,83 @@ const showWelcome = computed(() => !isChatting.value); const welcomeGreet = computed(() => { const hour = new Date().getHours(); - if (hour < 6) return t('nanaAssistant.greet.night'); - if (hour < 12) return t('nanaAssistant.greet.morning'); - if (hour < 14) return t('nanaAssistant.greet.noon'); - if (hour < 18) return t('nanaAssistant.greet.afternoon'); - return t('nanaAssistant.greet.evening'); + if (hour < 6) return t('ediAssistant.greet.night'); + if (hour < 12) return t('ediAssistant.greet.morning'); + if (hour < 14) return t('ediAssistant.greet.noon'); + if (hour < 18) return t('ediAssistant.greet.afternoon'); + return t('ediAssistant.greet.evening'); }); const welcomeHeadline = computed(() => - t('nanaAssistant.welcomeHello', { greet: welcomeGreet.value }), + isOpsAudience.value + ? t('ediAssistant.ops.welcomeHello', { greet: welcomeGreet.value }) + : t('ediAssistant.welcomeHello', { greet: welcomeGreet.value }), ); +const welcomeSubText = computed(() => + isOpsAudience.value ? t('ediAssistant.ops.welcomeSub') : t('ediAssistant.welcomeSub'), +); + +const composerHintText = computed(() => { + if (!providerKey.value) { + return isOpsAudience.value ? t('ediAssistant.ops.hint') : t('ediAssistant.hint'); + } + return isOpsAudience.value ? t('ediAssistant.ops.hintLive') : t('ediAssistant.hintLive'); +}); + +type OpsQuickAction = { + id: 'pasteError' | 'allocation' | 'channelGuide' | 'orderGuide'; + titleKey: string; + descKey: string; + icon: Component; +}; + +const opsQuickActions: OpsQuickAction[] = [ + { + id: 'pasteError', + titleKey: 'ediAssistant.ops.quick.pasteError', + descKey: 'ediAssistant.ops.quick.pasteErrorDesc', + icon: IconMessage, + }, + { + id: 'allocation', + titleKey: 'ediAssistant.ops.quick.allocation', + descKey: 'ediAssistant.ops.quick.allocationDesc', + icon: IconSafe, + }, + { + id: 'channelGuide', + titleKey: 'ediAssistant.ops.quick.channelGuide', + descKey: 'ediAssistant.ops.quick.channelGuideDesc', + icon: IconPublic, + }, + { + id: 'orderGuide', + titleKey: 'ediAssistant.ops.quick.orderGuide', + descKey: 'ediAssistant.ops.quick.orderGuideDesc', + icon: IconFile, + }, +]; + +function runOpsQuickAction(id: OpsQuickAction['id']) { + if (id === 'channelGuide') { + router.push('/channel/guide'); + return; + } + if (id === 'orderGuide') { + router.push('/order/guide'); + return; + } + if (id === 'allocation') { + inputText.value = t('ediAssistant.ops.quick.allocationDraft'); + focusInput({ force: true }); + return; + } + // pasteError + inputText.value = ''; + focusInput({ force: true }); +} + const canSend = computed(() => Boolean(inputText.value.trim() && !chatLoading.value)); const composerPlaceholder = computed(() => ''); @@ -540,7 +777,7 @@ function getActiveThread() { function deriveThreadTitle(list: ChatMessage[]) { const firstUser = list.find((m) => m.role === 'user'); - if (!firstUser) return t('nanaAssistant.newChat'); + if (!firstUser) return t('ediAssistant.newChat'); const text = firstUser.content.trim(); return text.length > 28 ? `${text.slice(0, 28)}…` : text; } @@ -588,7 +825,7 @@ function saveThreads() { function createThread(setActive = true) { const thread: Thread = { id: newThreadId(), - title: t('nanaAssistant.newChat'), + title: t('ediAssistant.newChat'), updatedAt: Date.now(), messages: [], }; @@ -676,7 +913,7 @@ function startNewChat() { const thread = getActiveThread(); if (thread) { thread.waybillContext = { ...ctx }; - thread.title = getWaybillDisplayNo(ctx) || t('nanaAssistant.newChat'); + thread.title = getWaybillDisplayNo(ctx) || t('ediAssistant.newChat'); } waybillContext.value = ctx; inputText.value = getWaybillPrefillText(ctx); @@ -729,7 +966,7 @@ function ensureWelcomeMessage() { if (messages.value.length > 0) return; messages.value.push({ role: 'assistant', - content: t('nanaAssistant.welcomeMsg'), + content: t('ediAssistant.welcomeMsg'), }); saveThreads(); } @@ -772,10 +1009,10 @@ function copyWechatId() { navigator.clipboard .writeText(id) .then(() => { - Message.success(t('nanaAssistant.copyWechatSuccess')); + Message.success(t('ediAssistant.copyWechatSuccess')); }) .catch(() => { - Message.warning(t('nanaAssistant.copyWechatFailed')); + Message.warning(t('ediAssistant.copyWechatFailed')); }); } @@ -796,6 +1033,7 @@ function clearWaybillContext() { delete thread.waybillContext; saveThreads(); } + if (mode.value === 'float') return; const path = route.path.startsWith('/h5') ? '/h5/assistant' : '/assistant'; router.replace({ path }); } @@ -838,13 +1076,13 @@ async function refreshWaybillStatusLabel() { function resolveTagReply(tagId: string) { const def = quickTagDefs.find((tag) => tag.id === tagId); - if (!def) return t('nanaAssistant.emptyReply'); + if (!def) return t('ediAssistant.emptyReply'); if (def.track && waybillContext.value) { - return t('nanaAssistant.trackWaybillDemo', { no: waybillDisplayNo.value }); + return t('ediAssistant.trackWaybillDemo', { no: waybillDisplayNo.value }); } - if (def.track) return t('nanaAssistant.trackHint'); + if (def.track) return t('ediAssistant.trackHint'); if (def.replyKey) return t(def.replyKey); - return t('nanaAssistant.emptyReply'); + return t('ediAssistant.emptyReply'); } function isTrackQuestion(text: string) { @@ -855,10 +1093,10 @@ function isTrackQuestion(text: string) { /** 未接 AI 时的诚实提示,不再假装已理解并乱要「起运地」 */ function offlineReply(userText: string) { if (waybillContext.value && isTrackQuestion(userText)) { - return t('nanaAssistant.trackWaybillDemo', { no: waybillDisplayNo.value }); + return t('ediAssistant.trackWaybillDemo', { no: waybillDisplayNo.value }); } - if (providerLoading.value) return t('nanaAssistant.providerLoading'); - return t('nanaAssistant.aiUnavailable'); + if (providerLoading.value) return t('ediAssistant.providerLoading'); + return t('ediAssistant.aiUnavailable'); } function demoReplyDelay() { @@ -921,7 +1159,7 @@ async function askWaybillTrack() { if (chatLoading.value || !waybillContext.value) return; if (!gateH5LoginBeforeChat()) return; activeCapability.value = 'track'; - const text = t('nanaAssistant.waybillAutoAsk', { no: waybillDisplayNo.value }); + const text = t('ediAssistant.waybillAutoAsk', { no: waybillDisplayNo.value }); await sendUserText(text); } @@ -982,42 +1220,67 @@ async function sendQuickTag(tag: { id: string; label: string }) { function buildAgentMessages(userFacingMessages: ChatMessage[]) { const list: { role: string; content: string }[] = []; - if (waybillContext.value) { - list.push({ - role: 'system', - content: `用户当前关注运单号:${waybillDisplayNo.value}。查轨迹时可直接使用该单号调用 oms.track_query。`, - }); - } - const recentUserBlob = userFacingMessages .filter((m) => m.role === 'user') .slice(-4) .map((m) => m.content) .join('\n'); - const hintedOrderNo = extractOrderNo(recentUserBlob); - if (hintedOrderNo && !waybillContext.value) { + + if (isOpsAudience.value) { + const guide = buildOpsGuideContext(recentUserBlob, String(route.path || '')); + const links = guide.deepLinks.map((l) => `${l.title} ${l.path}`).join(';'); list.push({ role: 'system', - content: `用户消息中已出现单号「${hintedOrderNo}」。若在查轨迹,请立即用该单号调用 oms.track_query,不要再向用户索要单号。`, + content: + '【运营排障模式】禁止调用客户 MCP 工具(oms.price_check / oms.channel_guide / oms.track_query)。' + + `优先依据下列指引摘录作答;可引导同事打开:${links || '/channel/guide、/order/guide'}。` + + '摘录未覆盖时明确说「指引未写到」,给通用排查清单,勿编造菜单。', }); - } + if (guide.contextMarkdown) { + list.push({ + role: 'system', + content: `【模块指引摘录】\n${guide.contextMarkdown}`, + }); + } + if (waybillContext.value) { + list.push({ + role: 'system', + content: `同事当前关注运单号:${waybillDisplayNo.value}。排障时可请其对照运单上的待排货/预报失败原因。`, + }); + } + } else { + if (waybillContext.value) { + list.push({ + role: 'system', + content: `用户当前关注运单号:${waybillDisplayNo.value}。查轨迹时可直接使用该单号调用 oms.track_query。`, + }); + } - if (activeCapability.value) { - const cap = getCapability(activeCapability.value); - if (cap.id === 'guide') { + const hintedOrderNo = extractOrderNo(recentUserBlob); + if (hintedOrderNo && !waybillContext.value) { list.push({ role: 'system', - content: - '用户在问品名能不能寄/走什么渠道。必须调用 oms.channel_guide,参数形如 ' + - '{"productCode":"","productName":"","cargoName":"<从用户话提取的品名>"}。' + - '已知渠道再填 productCode/productName,否则留空。不要空回复。', - }); - } else { - list.push({ - role: 'system', - content: `用户当前意图偏向「${cap.toolKey}」。必填信息已齐时立刻调工具;不要索要起运地;不要空回复。`, + content: `用户消息中已出现单号「${hintedOrderNo}」。若在查轨迹,请立即用该单号调用 oms.track_query,不要再向用户索要单号。`, }); } + + if (activeCapability.value) { + const cap = getCapability(activeCapability.value); + if (cap.id === 'guide') { + list.push({ + role: 'system', + content: + '用户在问品名能不能寄/走什么渠道。必须调用 oms.channel_guide,参数形如 ' + + '{"productCode":"","productName":"","cargoName":"<从用户话提取的品名>"}。' + + '已知渠道再填 productCode/productName,否则留空。不要空回复。', + }); + } else { + list.push({ + role: 'system', + content: `用户当前意图偏向「${cap.toolKey}」。必填信息已齐时立刻调工具;不要索要起运地;不要空回复。`, + }); + } + } } // 只带最近几轮,避免历史把 token 打爆 const dialog = userFacingMessages @@ -1040,7 +1303,7 @@ function buildMissingCoach(capability: McpCapabilityId, missingKeys: string[]) { }) .filter(Boolean); if (!labels.length) return ''; - return t('nanaAssistant.mcp.missingAsk', { fields: labels.join('、') }); + return t('ediAssistant.mcp.missingAsk', { fields: labels.join('、') }); } async function sendUserText(text: string, presetReply?: string) { @@ -1069,8 +1332,8 @@ async function sendUserText(text: string, presetReply?: string) { .slice(-5) .map((m) => m.content); - // 仅在「明显缺必填」时本地追问;多轮上下文合并判断,避免反复要已经给过的信息 - if (providerKey.value && inferred) { + // 客户侧:仅在「明显缺必填」时本地追问;运营排障不走 MCP 字段教练 + if (!isOpsAudience.value && providerKey.value && inferred) { const missing = detectMissingFields(inferred, text, { hasWaybillContext: Boolean(waybillContext.value), priorTexts: priorTexts.slice(0, -1), @@ -1087,16 +1350,18 @@ async function sendUserText(text: string, presetReply?: string) { providerKey: providerKey.value, model: providerModel.value || undefined, messages: buildAgentMessages(messages.value), - maxToolRounds: 2, + maxToolRounds: isOpsAudience.value ? 1 : 2, + audience: isOpsAudience.value ? 'ops' : 'customer', + toolKeys: isOpsAudience.value ? [] : undefined, }); let content = String(res.content || '').trim(); if (!content && res.toolTraces?.length) { const ok = res.toolTraces.filter((x) => x.success).map((x) => x.toolKey).join('、'); content = ok - ? t('nanaAssistant.toolDoneEmpty', { tools: ok }) - : t('nanaAssistant.emptyReply'); + ? t('ediAssistant.toolDoneEmpty', { tools: ok }) + : t('ediAssistant.emptyReply'); } - if (!content) content = t('nanaAssistant.emptyReply'); + if (!content) content = t('ediAssistant.emptyReply'); messages.value.push({ role: 'assistant', content }); saveThreads(); return; @@ -1106,10 +1371,10 @@ async function sendUserText(text: string, presetReply?: string) { } catch (e: any) { if (presetReply !== undefined) return; const errMsg = String(e?.message || '').trim(); - Message.warning(errMsg || t('nanaAssistant.sendFailed')); + Message.warning(errMsg || t('ediAssistant.sendFailed')); messages.value.push({ role: 'assistant', - content: errMsg ? t('nanaAssistant.sendFailedDetail', { msg: errMsg }) : t('nanaAssistant.sendFailed'), + content: errMsg ? t('ediAssistant.sendFailedDetail', { msg: errMsg }) : t('ediAssistant.sendFailed'), }); saveThreads(); } finally { @@ -1125,11 +1390,23 @@ async function maybeAutoAskWaybillTrack(isNewThread: boolean) { await askWaybillTrack(); } +function onFloatChromePointerDown(e: PointerEvent) { + if (mode.value !== 'float') return; + if (e.button !== 0) return; + const target = e.target as HTMLElement | null; + if (target?.closest('button, a, input, textarea')) return; + emit('float-drag-start', e); +} + function goBack() { syncActiveThreadMessages(); saveThreads(); historyOpen.value = false; advisorDrawerOpen.value = false; + if (mode.value === 'float') { + emit('close'); + return; + } if (window.history.length > 1) { router.back(); return; @@ -1142,8 +1419,7 @@ function goBack() { router.push('/home/workplace'); } -async function applyWaybillContextFromRoute() { - const ctx = parseWaybillContextFromQuery(route.query); +async function applyWaybillContext(ctx: WaybillContext | null) { if (!ctx) { waybillContext.value = getActiveThread()?.waybillContext ?? null; await refreshWaybillStatusLabel(); @@ -1167,7 +1443,7 @@ async function applyWaybillContextFromRoute() { const thread = getActiveThread(); if (thread) { thread.waybillContext = { ...ctx }; - thread.title = getWaybillDisplayNo(ctx) || t('nanaAssistant.newChat'); + thread.title = getWaybillDisplayNo(ctx) || t('ediAssistant.newChat'); messages.value = []; } } @@ -1186,6 +1462,10 @@ async function applyWaybillContextFromRoute() { } } +async function applyWaybillContextFromRoute() { + await applyWaybillContext(parseWaybillContextFromQuery(route.query)); +} + function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') { if (advisorDrawerOpen.value) { @@ -1293,10 +1573,16 @@ onMounted(() => { if (!isCustomerH5Guest()) { loadProvider(); } - void applyWaybillContextFromRoute().then(() => applyPrefillFromRoute()); + const bootWaybill = + mode.value === 'float' + ? useEdiAdvisorPanel().consumePendingWaybillContext() + : parseWaybillContextFromQuery(route.query); + void applyWaybillContext(bootWaybill).then(() => { + if (mode.value === 'page') return applyPrefillFromRoute(); + }); window.addEventListener('keydown', onKeydown); // 手机/微信:禁止进页自动聚焦,避免整页被放大 - if (!shouldSkipAutoFocus() && !parseWaybillContextFromQuery(route.query)) { + if (!shouldSkipAutoFocus() && !bootWaybill) { nextTick(() => focusInput()); } }); diff --git a/src/components/EdiAssistant/EdiAvatar.vue b/src/components/EdiAssistant/EdiAvatar.vue new file mode 100644 index 0000000..abb68c9 --- /dev/null +++ b/src/components/EdiAssistant/EdiAvatar.vue @@ -0,0 +1,74 @@ + + + diff --git a/src/components/NanaAssistant/NanaBatchJobsDrawer.vue b/src/components/EdiAssistant/EdiBatchJobsDrawer.vue similarity index 80% rename from src/components/NanaAssistant/NanaBatchJobsDrawer.vue rename to src/components/EdiAssistant/EdiBatchJobsDrawer.vue index 97c9456..7778736 100644 --- a/src/components/NanaAssistant/NanaBatchJobsDrawer.vue +++ b/src/components/EdiAssistant/EdiBatchJobsDrawer.vue @@ -8,7 +8,7 @@ getOrderBatchJobList, type ParsedOrderBatchJob, } from '@/api/order'; - import { useNanaBatchPanel } from '@/composables/useNanaBatchPanel'; + import { useEdiBatchPanel } from '@/composables/useEdiBatchPanel'; import { BATCH_JOB_TERMINAL_STATUSES, getBatchActionLabelKey, @@ -16,7 +16,7 @@ } from '@/constants/orderBatchAction'; import BatchJobDetailDrawer from '@/views/order/batchJobs/components/BatchJobDetailDrawer.vue'; - defineOptions({ name: 'NanaBatchJobsPanel' }); + defineOptions({ name: 'EdiBatchJobsPanel' }); const POLL_MS = 3000; const PAGE_SIZE = 3; @@ -27,7 +27,7 @@ const { t } = useI18n(); const router = useRouter(); const { visible, highlightJobId, close, setActiveJobCount, setRingPercent, fabAnchor } = - useNanaBatchPanel(); + useEdiBatchPanel(); const loading = ref(false); const jobs = ref([]); @@ -134,7 +134,7 @@ if (!visible.value || detailVisible.value) return; const panel = panelRef.value; if (panel && e.target instanceof Node && panel.contains(e.target)) return; - const fab = document.querySelector('.nana-fab-host'); + const fab = document.querySelector('.edi-fab-host'); if (fab && e.target instanceof Node && fab.contains(e.target)) return; close(); } @@ -170,38 +170,38 @@ + diff --git a/src/components/NanaAssistant/NanaComposer.vue b/src/components/EdiAssistant/EdiComposer.vue similarity index 100% rename from src/components/NanaAssistant/NanaComposer.vue rename to src/components/EdiAssistant/EdiComposer.vue diff --git a/src/components/NanaAssistant/ai-advisor.css b/src/components/EdiAssistant/ai-advisor.css similarity index 71% rename from src/components/NanaAssistant/ai-advisor.css rename to src/components/EdiAssistant/ai-advisor.css index 76715b9..f4d8a04 100644 --- a/src/components/NanaAssistant/ai-advisor.css +++ b/src/components/EdiAssistant/ai-advisor.css @@ -12,14 +12,313 @@ } .ai-advisor-shell--page { + --ai-shell-surface: var(--app-elevated-bg, #fff); + --ai-sidebar-surface: color-mix(in srgb, var(--app-page-bg, #f0f3f4) 88%, #fff); position: relative; inset: auto; z-index: auto; flex: 1; - min-height: 0; + width: 100%; height: 100%; - animation: none; + min-height: 0; box-sizing: border-box; + animation: none; +} + +/* FAB 旁浮窗:更大阅读区、可拖可拉 */ +.ai-advisor-shell--float { + --ai-thread-max: 100%; + --ai-shell-surface: var(--app-elevated-bg, #fff); + --ai-sidebar-surface: color-mix(in srgb, var(--app-page-bg, #f0f3f4) 90%, #fff); + position: relative; + inset: auto; + z-index: auto; + width: 100%; + height: 100%; + min-height: 0; + box-sizing: border-box; + animation: none; + border-radius: 20px; + overflow: hidden; +} + +.ai-advisor-shell--float .ai-shell-bg { + border-radius: 20px; + background: + radial-gradient(ellipse 90% 50% at 0% 0%, color-mix(in srgb, var(--app-primary-color, #1d7281) 8%, transparent) 0%, transparent 55%), + var(--ai-shell-surface); +} + +.ai-advisor-shell--float .ai-advisor-layout { + position: relative; + max-width: none; + width: 100%; + height: 100%; + margin: 0; + padding: 0; + gap: 0; + overflow: hidden; + isolation: isolate; +} + +.ai-advisor-shell--float .ai-history-sidebar { + position: absolute; + z-index: 6; + top: 0; + left: 0; + bottom: 0; + width: min(268px, 72%); + margin: 0; + padding: 14px 12px 16px; + border: none; + border-right: 1px solid color-mix(in srgb, var(--color-text-1, #1d2129) 8%, transparent); + border-radius: 0; + box-shadow: 12px 0 28px rgba(15, 23, 42, 0.1); + background: var(--ai-sidebar-surface); + transform: translateX(-105%); + transition: transform 0.22s cubic-bezier(0.22, 1, 0.36, 1); + pointer-events: auto; +} + +.ai-advisor-shell--float.ai-history-open .ai-history-sidebar { + transform: translateX(0); +} + +.ai-advisor-shell--float .ai-history-backdrop { + display: block; + position: absolute; + inset: 0; + z-index: 5; + border: none; + margin: 0; + padding: 0; + background: rgba(15, 23, 42, 0.22); + opacity: 0; + pointer-events: none; + transition: opacity 0.18s ease; +} + +.ai-advisor-shell--float.ai-history-open .ai-history-backdrop { + opacity: 1; + pointer-events: auto; +} + +.ai-advisor-shell--float .ai-sidebar-brand { + display: none; +} + +.ai-advisor-shell--float .ai-advisor-app { + position: relative; + z-index: 1; + border: none; + border-radius: 0; + box-shadow: none; + background: transparent; + backdrop-filter: none; + padding: 0; + width: 100%; +} + +.ai-advisor-shell--float .ai-app-bar--float { + max-width: none; + margin: 0; + gap: 10px; + padding: 12px 14px 10px; + border-bottom: 1px solid color-mix(in srgb, var(--color-text-1, #1d2129) 7%, transparent); + cursor: grab; + user-select: none; + touch-action: none; + background: color-mix(in srgb, var(--ai-shell-surface) 88%, transparent); + backdrop-filter: blur(8px); +} + +.ai-advisor-shell--float .ai-app-bar--float:active { + cursor: grabbing; +} + +.ai-advisor-shell--float .ai-float-avatar.edi-fab-wrap, +.ai-advisor-shell--float .ai-float-avatar.edi-fab-wrap--sm { + width: 36px; + height: 36px; + flex-shrink: 0; + margin: 0; + pointer-events: none; +} + +.ai-advisor-shell--float .ai-float-heading { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; + gap: 2px; +} + +.ai-advisor-shell--float .ai-float-title { + margin: 0; + font-size: 0.95rem; + font-weight: 750; + letter-spacing: -0.01em; + color: var(--color-text-1, #1d2129); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.ai-advisor-shell--float .ai-float-sub { + margin: 0; + font-size: 0.72rem; + line-height: 1.35; + color: var(--color-text-3, #86909c); + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + +.ai-advisor-shell--float .ai-app-bar__actions { + display: inline-flex; + align-items: center; + gap: 4px; + margin-left: auto; +} + +.ai-advisor-shell--float .ai-float-icon-btn { + display: inline-flex; + align-items: center; + justify-content: center; + width: 34px; + height: 34px; + border: none; + border-radius: 10px; + background: transparent; + color: var(--color-text-2, #4e5969); + cursor: pointer; + transition: background 0.15s ease, color 0.15s ease; +} + +.ai-advisor-shell--float .ai-float-icon-btn:hover:not(:disabled) { + background: var(--color-fill-2, #f2f3f5); + color: var(--color-text-1, #1d2129); +} + +.ai-advisor-shell--float .ai-float-icon-btn:disabled { + opacity: 0.45; + cursor: not-allowed; +} + +.ai-advisor-shell--float .ai-float-icon-btn--close:hover:not(:disabled) { + background: color-mix(in srgb, #f53f3f 12%, transparent); + color: #f53f3f; +} + +.ai-advisor-shell--float .ai-waybill-context { + max-width: none; + margin: 0 12px; + padding: 8px 10px; + border-radius: 12px; + background: color-mix(in srgb, var(--app-primary-color, #1d7281) 6%, transparent); + border: 1px solid color-mix(in srgb, var(--app-primary-color, #1d7281) 12%, transparent); +} + +.ai-advisor-shell--float .ai-app-main { + padding: 12px 14px 18px; +} + +.ai-advisor-shell--float .ai-app-main--welcome { + justify-content: flex-start; + padding-top: 18px; +} + +.ai-advisor-shell--float .ai-welcome { + padding-top: 4px; +} + +.ai-advisor-shell--float .ai-welcome__hero { + flex-direction: row; + align-items: flex-start; + text-align: left; + gap: 12px; + padding: 4px 2px 14px; +} + +.ai-advisor-shell--float .ai-app-main--welcome .ai-welcome__hero { + flex-direction: row; + align-items: flex-start; + text-align: left; +} + +.ai-advisor-shell--float .ai-app-main--welcome .ai-welcome__copy { + align-items: flex-start; +} + +.ai-advisor-shell--float .ai-app-main--welcome .ai-welcome__hero h2 { + font-size: 1.2rem; + letter-spacing: -0.02em; +} + +.ai-advisor-shell--float .ai-app-main--welcome .ai-welcome__hero p { + max-width: none; + font-size: 0.84rem; +} + +.ai-advisor-shell--float .ai-welcome__avatar.edi-fab-wrap, +.ai-advisor-shell--float .ai-welcome__avatar.edi-fab-wrap--sm { + width: 44px; + height: 44px; +} + +.ai-advisor-shell--float .ai-mcp-grid { + grid-template-columns: repeat(2, minmax(0, 1fr)); + gap: 10px; +} + +.ai-advisor-shell--float .ai-mcp-card { + min-height: 78px; + padding: 12px 12px; + border-radius: 14px; + border: 1px solid color-mix(in srgb, var(--color-text-1, #1d2129) 8%, transparent); + background: color-mix(in srgb, var(--ai-shell-surface) 70%, var(--color-fill-2, #f7f8fa)); + transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease; +} + +.ai-advisor-shell--float .ai-mcp-card:hover:not(:disabled) { + border-color: color-mix(in srgb, var(--app-primary-color, #1d7281) 35%, transparent); + background: var(--ai-shell-surface); + transform: translateY(-1px); +} + +.ai-advisor-shell--float .ai-composer-wrap { + max-width: none; + margin: 0; + padding: 10px 14px 14px; + background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--ai-shell-surface) 92%, #fff) 28%); +} + +.ai-advisor-shell--float .ai-composer { + border-radius: 18px; + padding: 10px 12px; + border: 1px solid color-mix(in srgb, var(--color-text-1, #1d2129) 10%, transparent); + box-shadow: + 0 1px 0 rgba(255, 255, 255, 0.7) inset, + 0 10px 24px rgba(27, 42, 107, 0.07); +} + +.ai-advisor-shell--float .ai-composer-hint { + font-size: 0.7rem; +} + +.ai-advisor-shell--float .edi-chat-dialog.ai-messages { + max-width: none; + gap: 18px; + padding-top: 4px; +} + +.ai-advisor-shell--float .edi-chat-dialog .ai-msg-bubble { + max-width: min(86%, 24rem); +} + +.ai-advisor-shell--float .edi-chat-dialog .ai-msg-row--assistant .ai-msg-text { + font-size: 0.95rem; + line-height: 1.7; } @keyframes ai-shell-in { @@ -31,32 +330,79 @@ } } +/* Page: edge-to-edge shell — sidebar | main, no floating cards */ .ai-advisor-shell--page .ai-advisor-layout { - max-width: min(1520px, 100%); + max-width: none; + width: 100%; height: 100%; - margin: 0 auto; - padding: 12px; + margin: 0; + padding: 0; box-sizing: border-box; + gap: 0; } .ai-advisor-shell--page .ai-shell-bg { - border-radius: 16px; + border-radius: 0; + background: var(--ai-shell-surface); +} + +.ai-advisor-shell--page .ai-history-sidebar { + width: 260px; + margin: 0; + padding: 14px 12px 16px; + border: none; + border-right: 1px solid color-mix(in srgb, var(--color-text-1, #1d2129) 8%, transparent); + border-radius: 0; + box-shadow: none; + backdrop-filter: none; + -webkit-backdrop-filter: none; + background: var(--ai-sidebar-surface); +} + +.ai-advisor-shell--page .ai-advisor-app { + border: none; + border-radius: 0; + box-shadow: none; + background: var(--ai-shell-surface); + backdrop-filter: none; + -webkit-backdrop-filter: none; + padding: 10px 0 14px; } .ai-advisor-shell--page .ai-app-bar { border-bottom: none; - padding: 0 0 8px; + padding: 0 16px 4px; background: transparent; + max-width: var(--ai-thread-max, 48rem); + width: 100%; + margin-inline: auto; + box-sizing: border-box; } .ai-advisor-shell--page .ai-app-bar--waybill { padding-bottom: 4px; } +.ai-advisor-shell--page .ai-waybill-context { + max-width: var(--ai-thread-max, 48rem); + width: 100%; + margin-inline: auto; + box-sizing: border-box; +} + +.ai-advisor-shell--page .ai-app-main { + padding-left: 16px; + padding-right: 16px; +} + .ai-advisor-shell--page .ai-composer-wrap { border-top: none; background: transparent; - padding-top: 4px; + padding: 10px 16px 6px; + max-width: var(--ai-thread-max, 48rem); + width: 100%; + margin-inline: auto; + box-sizing: border-box; } @media (min-width: 769px) { @@ -72,6 +418,7 @@ radial-gradient(ellipse 80% 60% at 50% -10%, rgba(45, 140, 140, 0.12) 0%, transparent 55%), radial-gradient(ellipse 50% 40% at 100% 100%, rgba(255, 180, 0, 0.06) 0%, transparent 50%), var(--kc-page-bg, var(--app-page-bg)); + pointer-events: none; } .ai-advisor-layout { @@ -371,6 +718,7 @@ } .ai-advisor-app { + --ai-thread-max: 48rem; position: relative; z-index: 1; display: flex; @@ -656,8 +1004,15 @@ flex: 1; min-height: 0; overflow-y: auto; - padding: 8px 2px 12px; + padding: 12px 12px 28px; scroll-behavior: smooth; + display: flex; + flex-direction: column; + align-items: stretch; +} + +.ai-app-main--welcome { + justify-content: center; } .ai-app-main::-webkit-scrollbar { @@ -671,7 +1026,11 @@ /* —— Welcome (empty state) —— */ .ai-welcome { - padding: 8px 0 24px; + width: 100%; + max-width: var(--ai-thread-max, 48rem); + margin-inline: auto; + padding: 12px 0 8px; + box-sizing: border-box; animation: ai-fade-up 0.45s ease 0.1s both; } @@ -693,13 +1052,34 @@ .ai-welcome__hero { display: flex; align-items: flex-start; - gap: 12px; + gap: 14px; text-align: left; - padding: 12px 4px 16px; + padding: 8px 4px 20px; } -.ai-welcome__avatar.nana-fab-wrap, -.ai-welcome__avatar.nana-fab-wrap--sm { +.ai-app-main--welcome .ai-welcome__hero { + flex-direction: column; + align-items: center; + text-align: center; + padding-bottom: 28px; +} + +.ai-app-main--welcome .ai-welcome__copy { + display: flex; + flex-direction: column; + align-items: center; +} + +.ai-app-main--welcome .ai-welcome__hero h2 { + font-size: clamp(1.35rem, 3.2vw, 1.75rem); +} + +.ai-app-main--welcome .ai-welcome__hero p { + max-width: 36rem; +} + +.ai-welcome__avatar.edi-fab-wrap, +.ai-welcome__avatar.edi-fab-wrap--sm { flex-shrink: 0; margin: 0; width: 48px; @@ -924,7 +1304,7 @@ display: flex; } -/* 会话气泡/阅读流由 NanaChatDialog + nana-chat.css 统一提供 */ +/* 会话气泡/阅读流由 EdiChatDialog + edi-chat.css 统一提供 */ /* Compact chips(跟进条仍可在壳层单独使用) */ .ai-followup { @@ -971,15 +1351,21 @@ /* —— Composer (sticky) —— */ .ai-composer-wrap { flex-shrink: 0; - padding: 8px 2px 0; + width: 100%; + max-width: var(--ai-thread-max, 48rem); + margin-inline: auto; + padding: 8px 12px 0; + box-sizing: border-box; } .ai-composer { - padding: 8px; - border-radius: 16px; - border: 1px solid rgba(27, 42, 107, 0.08); + padding: 10px 12px; + border-radius: 24px; + border: 1px solid rgba(27, 42, 107, 0.1); background: var(--app-elevated-bg); - box-shadow: inset 0 1px 0 transparent; + box-shadow: + 0 0 0 1px rgba(255, 255, 255, 0.4) inset, + 0 8px 28px rgba(27, 42, 107, 0.08); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); } @@ -1145,7 +1531,23 @@ @media (max-width: 768px) { .ai-advisor-shell--page .ai-advisor-layout { - padding: 8px; + padding: 0; + } + + .ai-advisor-shell--page .ai-advisor-app { + padding: 6px 0 10px; + } + + .ai-advisor-shell--page .ai-app-bar, + .ai-advisor-shell--page .ai-app-main, + .ai-advisor-shell--page .ai-composer-wrap { + padding-left: 12px; + padding-right: 12px; + } + + .ai-advisor-shell--page .ai-composer-wrap { + padding-top: 8px; + padding-bottom: 4px; } .ai-advisor-layout { @@ -1339,7 +1741,7 @@ font-size: 0.95rem; } -.ai-welcome__avatar.nana-fab-wrap { +.ai-welcome__avatar.edi-fab-wrap { display: inline-block; } @@ -1558,8 +1960,8 @@ color: var(--kc-secondary, #6a75b8); } -/* —— Nana avatar (FAB visual + chat sizes) —— */ -.nana-fab-wrap { +/* —— Edi avatar (FAB visual + chat sizes) —— */ +.edi-fab-wrap { position: relative; display: block; flex-shrink: 0; @@ -1567,50 +1969,90 @@ height: 64px; } -.nana-fab-wrap--sm { +.edi-fab-wrap--sm { width: 32px; height: 32px; } -.nana-fab-wrap--md { +.edi-fab-wrap--md { width: 64px; height: 64px; } -.nana-fab-wrap--lg { +.edi-fab-wrap--lg { width: 72px; height: 72px; } -.nana-fab-wrap--sm .nana-fab__pulse { +.edi-fab-wrap--sm .edi-fab__pulse { inset: 1px; border-width: 1px; } -.nana-fab-wrap--sm .nana-fab__img { - filter: drop-shadow(0 2px 6px rgba(45, 140, 140, 0.22)); +.edi-fab-wrap--sm .edi-fab__img { + filter: drop-shadow(0 2px 6px rgba(255, 122, 24, 0.28)); } -.nana-fab__img { +.edi-fab__img { width: 100%; height: 100%; object-fit: contain; - filter: drop-shadow(0 6px 16px rgba(45, 140, 140, 0.28)); + filter: drop-shadow(0 6px 16px rgba(255, 122, 24, 0.35)); pointer-events: none; - transition: transform 0.2s ease; + transform-origin: 50% 78%; + transition: transform 0.2s ease, filter 0.2s ease; } -.nana-fab__pulse { +/* + * 更好的静态图做法: + * 1) 轻呼吸(持续但克制) + * 2) 近场跟视(由 --edi-lean-* 驱动) + * 避免一直左右晃,那种更像廉价循环。 + */ +.edi-fab-wrap.is-animated { + transform: translate3d( + calc(var(--edi-lean-x, 0) * 5px), + calc(var(--edi-lean-y, 0) * 4px), + 0 + ) + rotate(calc(var(--edi-lean-x, 0) * 6deg)); + transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1); + will-change: transform; +} + +/* 静态图才叠 CSS 呼吸;live webp 自带呼吸+眨眼,避免双重动效 */ +.edi-fab-wrap.is-animated:not(.is-live) .edi-fab__img { + animation: edi-idle-breathe 4.6s ease-in-out infinite; + will-change: transform, filter; +} + +.edi-fab-wrap.is-live .edi-fab__img { + animation: none; +} + +@keyframes edi-idle-breathe { + 0%, + 100% { + transform: translateY(0) scale(1); + filter: drop-shadow(0 6px 14px rgba(255, 122, 24, 0.3)); + } + 50% { + transform: translateY(-3px) scale(1.035); + filter: drop-shadow(0 10px 18px rgba(255, 122, 24, 0.4)); + } +} + +.edi-fab__pulse { position: absolute; inset: 4px; border-radius: 50%; - border: 2px solid var(--app-primary-color, #2d8c8c); + border: 2px solid #ff7a18; opacity: 0; - animation: nana-pulse 2.4s ease-out infinite; + animation: edi-pulse 2.4s ease-out infinite; pointer-events: none; } -@keyframes nana-pulse { +@keyframes edi-pulse { 0% { transform: scale(0.9); opacity: 0.55; @@ -1626,7 +2068,7 @@ } /* —— Draggable FAB host —— */ -.nana-fab-host { +.edi-fab-host { position: fixed; z-index: 9998; cursor: grab; @@ -1634,10 +2076,27 @@ user-select: none; } -.nana-fab-host.is-dragging { +.edi-fab-host.is-dragging { cursor: grabbing; } -.nana-fab-host:hover:not(.is-dragging) .nana-fab__img { - transform: scale(1.06); +.edi-fab-host.is-dragging .edi-fab-wrap.is-animated, +.edi-fab-host.is-attention .edi-fab-wrap.is-animated, +.edi-fab-host.is-idle-nod .edi-fab-wrap.is-animated { + transition: none; + transform: none; +} + +.edi-fab-host.is-dragging .edi-fab-wrap.is-animated .edi-fab__img, +.edi-fab-host.is-attention .edi-fab-wrap.is-animated .edi-fab__img, +.edi-fab-host.is-idle-nod .edi-fab-wrap.is-animated .edi-fab__img { + animation: none; +} + +@media (prefers-reduced-motion: reduce) { + .edi-fab-wrap.is-animated, + .edi-fab-wrap.is-animated .edi-fab__img, + .edi-fab__pulse { + animation: none !important; + } } diff --git a/src/components/EdiAssistant/edi-chat.css b/src/components/EdiAssistant/edi-chat.css new file mode 100644 index 0000000..07d5126 --- /dev/null +++ b/src/components/EdiAssistant/edi-chat.css @@ -0,0 +1,159 @@ +/* Edi 公共会话流:ChatGPT 式居中阅读列 + FAB 同源头像 */ + +.edi-chat-dialog.ai-messages { + display: none; + flex-direction: column; + gap: 26px; + width: 100%; + max-width: var(--ai-thread-max, 48rem); + margin-inline: auto; + padding: 8px 0 20px; + box-sizing: border-box; +} + +.edi-chat-dialog.ai-messages.is-active { + display: flex; +} + +.edi-chat-dialog .ai-msg-row { + display: flex; + gap: 14px; + align-items: flex-start; + max-width: 100%; + width: 100%; + animation: edi-chat-msg-in 0.3s ease; +} + +@keyframes edi-chat-msg-in { + from { + opacity: 0; + transform: translateY(8px); + } + to { + opacity: 1; + transform: translateY(0); + } +} + +.edi-chat-dialog .ai-msg-row--user { + justify-content: flex-end; + align-self: stretch; +} + +.edi-chat-dialog .ai-msg-row--assistant { + align-self: stretch; + width: 100%; +} + +.edi-chat-dialog .ai-msg-edi.edi-fab-wrap, +.edi-chat-dialog .ai-msg-row--assistant .edi-fab-wrap { + position: relative; + display: block; + flex-shrink: 0; + width: 32px; + height: 32px; + margin-top: 4px; +} + +.edi-chat-dialog .ai-msg-edi .edi-fab__img, +.edi-chat-dialog .ai-msg-row--assistant .edi-fab__img { + width: 100%; + height: 100%; + object-fit: contain; + filter: drop-shadow(0 3px 8px rgba(255, 122, 24, 0.32)); + pointer-events: none; +} + +.edi-chat-dialog .ai-msg-edi .edi-fab__pulse, +.edi-chat-dialog .ai-msg-row--assistant .edi-fab__pulse { + position: absolute; + inset: 1px; + border-radius: 50%; + border: 1.5px solid #ff7a18; + opacity: 0; + animation: edi-pulse 2.4s ease-out infinite; + pointer-events: none; +} + +.edi-chat-dialog .ai-msg-body { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; + gap: 12px; + color: var(--ai-ink, var(--color-text-1)); +} + +.edi-chat-dialog .ai-msg-body--typing { + flex-direction: row; + align-items: center; + gap: 5px; + min-height: 32px; + padding: 8px 0; +} + +.edi-chat-dialog .ai-msg-bubble { + max-width: min(75%, 36rem); + padding: 12px 16px; + border-radius: 18px; + font-size: 0.95rem; + line-height: 1.6; + white-space: pre-wrap; + word-break: break-word; +} + +.edi-chat-dialog .ai-msg-row--user .ai-msg-bubble { + background: var(--ai-action, var(--app-primary-color, #2d8c8c)); + color: #fff; + border-bottom-right-radius: 6px; + box-shadow: 0 8px 20px color-mix(in srgb, var(--ai-action, var(--app-primary-color, #2d8c8c)) 18%, transparent); +} + +.edi-chat-dialog .ai-msg-text { + margin: 0; + white-space: pre-wrap; + word-break: break-word; +} + +.edi-chat-dialog .ai-msg-row--assistant .ai-msg-text { + font-size: 1rem; + line-height: 1.75; + letter-spacing: -0.011em; + color: var(--ai-ink, var(--color-text-1)); +} + +.edi-chat-dialog .ai-msg-followups { + display: flex; + flex-wrap: wrap; + gap: 8px; + padding-top: 4px; +} + +.edi-chat-dialog .ai-msg-row--typing .ai-msg-body--typing span { + width: 7px; + height: 7px; + border-radius: 50%; + background: var(--ai-muted, var(--color-text-3, #86909c)); + animation: edi-chat-typing 1.2s ease-in-out infinite; +} + +.edi-chat-dialog .ai-msg-row--typing .ai-msg-body--typing span:nth-child(2) { + animation-delay: 0.15s; +} + +.edi-chat-dialog .ai-msg-row--typing .ai-msg-body--typing span:nth-child(3) { + animation-delay: 0.3s; +} + +@keyframes edi-chat-typing { + 0%, + 80%, + 100% { + opacity: 0.35; + transform: scale(0.85); + } + 40% { + opacity: 1; + transform: scale(1); + } +} diff --git a/src/components/EdiAssistant/index.vue b/src/components/EdiAssistant/index.vue new file mode 100644 index 0000000..a82b855 --- /dev/null +++ b/src/components/EdiAssistant/index.vue @@ -0,0 +1,982 @@ + + + + + + + diff --git a/src/components/NanaAssistant/NanaAvatar.vue b/src/components/NanaAssistant/NanaAvatar.vue deleted file mode 100644 index 0e128ea..0000000 --- a/src/components/NanaAssistant/NanaAvatar.vue +++ /dev/null @@ -1,21 +0,0 @@ - - - diff --git a/src/components/NanaAssistant/index.vue b/src/components/NanaAssistant/index.vue deleted file mode 100644 index ac5e411..0000000 --- a/src/components/NanaAssistant/index.vue +++ /dev/null @@ -1,575 +0,0 @@ - - - - - - - diff --git a/src/components/NanaAssistant/nana-chat.css b/src/components/NanaAssistant/nana-chat.css deleted file mode 100644 index 375d715..0000000 --- a/src/components/NanaAssistant/nana-chat.css +++ /dev/null @@ -1,157 +0,0 @@ -/* Nana 公共会话流:与 FAB 同源头像 + 阅读流排版 */ - -.nana-chat-dialog.ai-messages { - display: none; - flex-direction: column; - gap: 18px; - width: 100%; - max-width: min(720px, 100%); - margin-inline: auto; - padding: 8px 0 16px; -} - -.nana-chat-dialog.ai-messages.is-active { - display: flex; -} - -.nana-chat-dialog .ai-msg-row { - display: flex; - gap: 12px; - align-items: flex-start; - max-width: 100%; - animation: nana-chat-msg-in 0.3s ease; -} - -@keyframes nana-chat-msg-in { - from { - opacity: 0; - transform: translateY(8px); - } - to { - opacity: 1; - transform: translateY(0); - } -} - -.nana-chat-dialog .ai-msg-row--user { - justify-content: flex-end; - align-self: stretch; -} - -.nana-chat-dialog .ai-msg-row--assistant { - align-self: stretch; - width: 100%; -} - -.nana-chat-dialog .ai-msg-nana.nana-fab-wrap, -.nana-chat-dialog .ai-msg-row--assistant .nana-fab-wrap { - position: relative; - display: block; - flex-shrink: 0; - width: 36px; - height: 36px; - margin-top: 2px; -} - -.nana-chat-dialog .ai-msg-nana .nana-fab__img, -.nana-chat-dialog .ai-msg-row--assistant .nana-fab__img { - width: 100%; - height: 100%; - object-fit: contain; - filter: drop-shadow(0 3px 8px rgba(45, 140, 140, 0.28)); - pointer-events: none; -} - -.nana-chat-dialog .ai-msg-nana .nana-fab__pulse, -.nana-chat-dialog .ai-msg-row--assistant .nana-fab__pulse { - position: absolute; - inset: 1px; - border-radius: 50%; - border: 1.5px solid var(--app-primary-color, #2d8c8c); - opacity: 0; - animation: nana-pulse 2.4s ease-out infinite; - pointer-events: none; -} - -.nana-chat-dialog .ai-msg-body { - flex: 1; - min-width: 0; - display: flex; - flex-direction: column; - gap: 12px; - color: var(--ai-ink, var(--color-text-1)); -} - -.nana-chat-dialog .ai-msg-body--typing { - flex-direction: row; - align-items: center; - gap: 5px; - min-height: 36px; - padding: 8px 0; -} - -.nana-chat-dialog .ai-msg-bubble { - max-width: min(520px, 86%); - padding: 11px 15px; - border-radius: 18px; - font-size: 0.94rem; - line-height: 1.55; - white-space: pre-wrap; - word-break: break-word; -} - -.nana-chat-dialog .ai-msg-row--user .ai-msg-bubble { - background: var(--ai-action, var(--app-primary-color, #2d8c8c)); - color: #fff; - border-bottom-right-radius: 6px; - box-shadow: 0 8px 20px color-mix(in srgb, var(--ai-action, var(--app-primary-color, #2d8c8c)) 18%, transparent); -} - -.nana-chat-dialog .ai-msg-text { - margin: 0; - white-space: pre-wrap; - word-break: break-word; -} - -.nana-chat-dialog .ai-msg-row--assistant .ai-msg-text { - font-size: 0.98rem; - line-height: 1.68; - letter-spacing: -0.01em; - color: var(--ai-ink, var(--color-text-1)); -} - -.nana-chat-dialog .ai-msg-followups { - display: flex; - flex-wrap: wrap; - gap: 8px; - padding-top: 2px; -} - -.nana-chat-dialog .ai-msg-row--typing .ai-msg-body--typing span { - width: 7px; - height: 7px; - border-radius: 50%; - background: var(--ai-muted, var(--color-text-3, #86909c)); - animation: nana-chat-typing 1.2s ease-in-out infinite; -} - -.nana-chat-dialog .ai-msg-row--typing .ai-msg-body--typing span:nth-child(2) { - animation-delay: 0.15s; -} - -.nana-chat-dialog .ai-msg-row--typing .ai-msg-body--typing span:nth-child(3) { - animation-delay: 0.3s; -} - -@keyframes nana-chat-typing { - 0%, - 80%, - 100% { - opacity: 0.35; - transform: scale(0.85); - } - 40% { - opacity: 1; - transform: scale(1); - } -} diff --git a/src/components/top-nav/RightTopMessage.vue b/src/components/top-nav/RightTopMessage.vue index b0c6028..ca857ed 100644 --- a/src/components/top-nav/RightTopMessage.vue +++ b/src/components/top-nav/RightTopMessage.vue @@ -1,5 +1,5 @@