This commit is contained in:
yin 2026-10-17 18:05:39 +08:00
parent 03d8ed615a
commit 91dd317867
26 changed files with 354 additions and 638 deletions

View File

@ -1,5 +1,5 @@
<script setup lang="ts">
import { onLaunch, onShow, onHide } from "@dcloudio/uni-app";
import { onLaunch, onShow } from "@dcloudio/uni-app";
import { watch } from "vue";
import { useUserStore } from "@/store/modules/user";
import { getToken } from "@/utils/auth";
@ -7,6 +7,7 @@ import { normalizeEntry, savePendingEntry, hasEntryAction } from "@/utils/entry"
import type { EntryLaunchOptions } from "@/utils/entry";
import { setUnauthorizedHandler } from "@/utils/auth-notify";
import { appendIdentityLog } from "@/utils/identity-log";
import { debugLog } from "@/utils/debug-log";
/**
* 捕获入口参数(扫码 / 链接 / 分享进入)
@ -21,7 +22,8 @@ import { appendIdentityLog } from "@/utils/identity-log";
function captureEntry(options?: EntryLaunchOptions) {
const entry = normalizeEntry(options);
if (!hasEntryAction(entry)) return;
console.log("[entry] 捕获入口参数", entry);
// 只记场景与目标页:**不打印 code**(扫码登录码 / 绑定码是凭证)
debugLog("[entry] 捕获入口参数", { scene: entry.scene, page: entry.page });
savePendingEntry(entry);
}
@ -89,11 +91,79 @@ onAppShow((options) => {
// 兜底:回前台时按当前状态再同步一次,避免出现「抽屉已经关了、tabBar 却没回来」
syncTabBar(useUserStore().authVisible);
});
onHide(() => {
console.log("App Hide");
});
</script>
<style lang="scss">
/* 必须写在 style 首行,且 style 标签需带 lang="scss" 属性 */
@import "uview-plus/index.scss";
/*
* ── 浅色主题锁(本项目不做深色模式)───────────────────────────────────────
*
* 设计前提:全站颜色是写死的浅色调(#f5f6fa 底 / #ffffff 卡片 / #303133 文字),
* 但 uview-plus 自带深色主题:
* 1. CSS 侧用 `@media (prefers-color-scheme: dark)` 把文字色改成 #f5f5f5 / #d1d5db,
* 而卡片仍是我们的白底 ⇒ **白底白字**(`up-cell` / 表单最明显);
* 2. JS 侧 `setThemePreference('system')` 会把弹层背景算成 #1c1c1e(深底深字)。
*
* 处理:启动时强制 uview 用 light(见 main.ts),并在这里把 CSS 变量钉回**浅色原值**
* (下面的值 = uview 浅色主题默认值,保证浅色下观感零变化)。
* ⚠️ 必须写在 `@import` 之后 —— 同为 `page` 选择器时后者生效。
*/
page {
/* 文字 / 边框 / 背景 */
--up-main-color: #303133;
--up-content-color: #606266;
--up-tips-color: #909193;
--up-light-color: #c0c4cc;
--up-border-color: #dadbde;
--up-bg-color: #f3f4f6;
--up-hover-bg-color: #e7ebf0;
--up-page-bg-color: #f3f4f6;
--up-card-bg-color: #ffffff;
--up-navbar-bg-color: #ffffff;
--up-disabled-color: #c8c9cc;
/* 功能色(深色主题的 *-light 是深底,白底上很突兀) */
--up-primary: #3c9cff;
--up-primary-dark: #398ade;
--up-primary-disabled: #9acafc;
--up-primary-light: #ecf5ff;
--up-warning: #f9ae3d;
--up-warning-dark: #f1a532;
--up-warning-disabled: #f9d39b;
--up-warning-light: #fdf6ec;
--up-success: #5ac725;
--up-success-dark: #53c21d;
--up-success-disabled: #a9e08f;
--up-success-light: #f5fff0;
--up-error: #f56c6c;
--up-error-dark: #e45656;
--up-error-disabled: #f7b2b2;
--up-error-light: #fef0f0;
--up-info: #909399;
--up-info-dark: #767a82;
--up-info-disabled: #c4c6c9;
--up-info-light: #f4f4f5;
/* uview 3.8 的 `--up-light-*` 别名:部分组件(如 up-cell)直接引用它们 */
--up-light-main-color: #303133;
--up-light-content-color: #606266;
--up-light-tips-color: #909193;
--up-light-light-color: #c0c4cc;
--up-light-border-color: #dadbde;
--up-light-bg-color: #f3f4f6;
--up-light-disabled-color: #c8c9cc;
--up-light-primary: #3c9cff;
--up-light-primary-dark: #398ade;
--up-light-primary-disabled: #9acafc;
--up-light-primary-light: #ecf5ff;
--up-light-warning: #f9ae3d;
--up-light-warning-light: #fdf6ec;
--up-light-success: #5ac725;
--up-light-success-light: #f5fff0;
--up-light-error: #f56c6c;
--up-light-error-light: #fef0f0;
--up-light-info: #909399;
--up-light-info-light: #f4f4f5;
}
</style>

View File

@ -16,13 +16,14 @@
import { onShow } from '@dcloudio/uni-app'
import { takePendingEntry } from '@/utils/entry'
import { handleEntryScene } from '@/router/scenes'
import { debugLog } from '@/utils/debug-log'
export function useEntryScene(): void {
onShow(() => {
const entry = takePendingEntry()
if (!entry) return
console.log('[entry] 消费待处理入口', entry)
debugLog('[entry] 消费待处理入口', { scene: entry.scene, page: entry.page })
handleEntryScene(entry).catch((err) => {
// 入口处理失败不能影响页面正常渲染
console.warn('[entry] 入口场景处理失败', err)

View File

@ -1,14 +1,14 @@
/**
* 首页入口区渲染状态
*
* 首页的入口区 = **动态菜单段**(`user.info` 的 menus × `PAGE_REGISTRY`)+ **本地「工具」段**
* 首页的入口区 = **动态菜单段**(`user.info` 的 menus × `PAGE_REGISTRY`)+ **本地「辅助工具」段**
* (`LOCAL_COMMON_ENTRIES`,前端写死),两段形态一致、动态段在前,合成逻辑在 `toHomeSections()`。
*
* 这个 composable 负责把「取数 / 加载态 / 空态文案 / 点击跳转」收口在一处,
* 页面只负责 `onShow` 调一次 `loadEntries()`,然后把 `sections` 交给模板。
*
* 登录态差异(2026-10-14 起):
* - 「工具」段不依赖接口 ⇒ **未登录时也一定有内容**,不再是「空态 + 去登录」那种形态
* - 「辅助工具」段不依赖接口 ⇒ **未登录时也一定有内容**,不再是「空态 + 去登录」那种形态
* - 未登录 / 未绑定 / 拉取失败只影响「动态菜单段」有无;已登录但拉不到菜单时,
* 页面用 `hasDynamicEntries` 判断并给一条**轻量重试提示**(工具段照常可用,不阻断)
* - `emptyStateProps` 只在**连本地段都为空**时才会走到(正常配置下不会出现,留作兜底)
@ -37,7 +37,7 @@ export interface UseEntrySectionsReturn {
/**
* 动态菜单段是否有内容
*
* 首页用它判断「已登录但菜单没拉回来」:此时「工具」段仍在,不白屏,
* 首页用它判断「已登录但菜单没拉回来」:此时「辅助工具」段仍在,不白屏,
* 只需在那之下补一条轻量重试提示(不用大块空态盖住可用内容)。
*/
hasDynamicEntries: ComputedRef<boolean>
@ -73,7 +73,7 @@ export function useEntrySections(
const loading = ref(false)
/** 入口分段 = 动态菜单段(在前)+ 本地「工具」段(固定在后,不登录也渲染) */
/** 入口分段 = 动态菜单段(在前)+ 本地「辅助工具」段(固定在后,不登录也渲染) */
const sections = computed(() => toHomeSections(permissionStore.entries, { looseTitle }))
/** 动态菜单段是否有内容(未登录 / 未绑定 / 失败时都为 false) */
@ -82,7 +82,7 @@ export function useEntrySections(
/**
* 空态文案(按“为什么是空的”分三种,**不要用服务端故障文案盖住未登录场景**)
*
* ⚠️ 只在**连本地「工具」段都为空**(`LOCAL_COMMON_ENTRIES` 为空)时才会显示 ——
* ⚠️ 只在**连本地「辅助工具」段都为空**(`LOCAL_COMMON_ENTRIES` 为空)时才会显示 ——
* 正常配置下首页永远至少有工具段,走不到这里,这里只做「绝不白屏」的兜底。
*
* | 场景 | 文案 | 动作 |

View File

@ -0,0 +1,60 @@
/**
* 协议与隐私入口(「我的」页等公共位置共用)
*
* 为什么抽成 composable:
* 这两个入口属于**全局信息**、且**不依赖登录**,放在多个页面里各写一份很容易出现
* 「一处改了另一处没改」的漂移(本项目已经踩过注释/文案漂移的坑)。
*
* 用法:
* ```vue
* const { agreementVisible, openAgreement, openPrivacyContract } = useLegalLinks()
* ```
* ```vue
* <!-- 页面模板里必须挂一份弹窗,`openAgreement()` 才有地方渲染 -->
* <agreement-modal v-model:show="agreementVisible" mode="view" />
* ```
*/
import { ref } from 'vue'
import type { Ref } from 'vue'
export interface UseLegalLinksReturn {
/** 《用户须知》弹窗是否显示(页面用 `v-model:show` 绑定 `<agreement-modal>`) */
agreementVisible: Ref<boolean>
/** 打开《用户须知》(`view` 只读模式,不要求滑到底) */
openAgreement: () => void
/** 打开微信官方《小程序用户隐私保护指引》 */
openPrivacyContract: () => void
}
export function useLegalLinks(): UseLegalLinksReturn {
const agreementVisible = ref(false)
const openAgreement = (): void => {
agreementVisible.value = true
}
/**
* 打开微信侧的《小程序用户隐私保护指引》
*
* 内容由公众平台后台「设置 → 服务内容声明 → 用户隐私保护指引」配置,不是小程序自己的页面;
* 用户在**未登录**状态下也可以查看(这正是它必须放在一级页的原因)。
*
* ⚠️ `wx.openPrivacyContract` 仅微信小程序端存在 ⇒ 必须条件编译,
* 否则 H5 / App 端运行时会报 `wx is not defined`。
*/
const openPrivacyContract = (): void => {
// #ifdef MP-WEIXIN
wx.openPrivacyContract({
fail: () => uni.$u.toast('打开失败,可在右上角「…」→ 设置 中查看')
})
return
// #endif
// #ifndef MP-WEIXIN
uni.$u.toast('请在微信小程序中查看')
// #endif
}
return { agreementVisible, openAgreement, openPrivacyContract }
}

View File

@ -10,6 +10,12 @@ export function createApp() {
app.use(Pinia.createPinia());
// 注册 uview-plus,注册后才可使用 uni.$u 等全局工具方法
app.use(uviewPlus);
// 本项目只有**一套浅色设计**(背景 / 卡片 / 文字都是写死的浅色调),不做深色模式。
// uview-plus 默认跟随系统主题,深色模式下会把文字算成 #f5f5f5、弹层背景算成 #1c1c1e
// ⇒ 白底白字 / 深底深字。这里强制锁成浅色(会写入 storage `u-theme-mode`,后续启动一致)。
uni.$u.setThemePreference('light')
return {
app,
Pinia,

View File

@ -59,6 +59,10 @@
上传模板代码 / 作为开放平台模板发布时,记得切回模板小程序 AppID。 */
"appid" : "wx31f8d1ee127bc64b",
"projectname" : "wms_mp_weixin",
/* 明确声明**不做**深色模式适配(本项目只有浅色设计)。
uni-app 会把该字段写进产物 app.json;
如将来要真正支持深色,需改 true + 配置 themeLocation 并逐页改造配色。 */
"darkmode" : false,
/* 微信开发者工具项目设置 */
"setting" : {
/* 是否校验安全域名与 TLS 版本:仅影响开发者工具内的请求校验,

View File

@ -43,18 +43,6 @@
{
"root": "pagesA",
"pages": [
{
"path": "demo/required",
"style": {
"navigationBarTitleText": "需登录示例"
}
},
{
"path": "test/index",
"style": {
"navigationBarTitleText": "测试页"
}
},
{
"path": "tools/calculator",
"style": {
@ -167,14 +155,6 @@
"name": "条形码",
"path": "pagesA/tools/barcode"
},
{
"name": "需登录示例页",
"path": "pagesA/demo/required"
},
{
"name": "测试页",
"path": "pagesA/test/index"
},
{
"name": "外仓商品",
"path": "pagesA/external-stock/list"

View File

@ -27,7 +27,7 @@
</view>
</view>
<!-- 功能入口:动态菜单分类段(在前)+ 本地「工具」段(在后,不登录也显示) -->
<!-- 功能入口:动态菜单分类段(在前)+ 本地「辅助工具」段(在后,不登录也显示) -->
<view class="card">
<!-- 登录后菜单尚未取到时的骨架屏(避免闪一下空态文案,也比转圈更贴合最终布局) -->
<view v-if="loading" class="skeleton">
@ -37,13 +37,13 @@
</view>
</view>
<!-- 入口分段:动态菜单段(在前,登录后才有)+ 本地「工具」段(固定在后,不登录也有) -->
<!-- 入口分段:动态菜单段(在前,登录后才有)+ 本地「辅助工具」段(固定在后,不登录也有) -->
<template v-else-if="sections.length">
<entry-sections :sections="sections" @select="onEntry"></entry-sections>
<!--
已登录、动态菜单却没回来(接口失败 / 后端未配)→ 只补一条**轻量重试**:
「工具」段照常可用,所以不用大块空态把页面盖住
「辅助工具」段照常可用,所以不用大块空态把页面盖住
-->
<view
v-if="showMenuError"
@ -85,22 +85,13 @@
<!-- 未登录:一句轻提示(不阻断浏览,只是说明登录后还能看到什么) -->
<view v-if="!isLogin" class="tip">登录以使用更多功能</view>
<!-- 运行信息:用于确认各端编译正常 -->
<!-- <view class="card">
<view class="card__title">运行信息</view>
<up-cell-group :border="false">
<up-cell title="uview-plus 版本" :value="version" :border="false"></up-cell>
<up-cell title="运行平台" :value="platform" :border="false"></up-cell>
</up-cell-group>
</view> -->
<!-- 登录抽屉:碰到需要登录的接口时会自动弹出(见 utils/request 的 auth 预判) -->
<auth-modal></auth-modal>
</view>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import { computed } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { useUserStore } from '@/store/modules/user'
import { useEntrySections } from '@/composables/useEntrySections'
@ -108,9 +99,6 @@ import { useEntryScene } from '@/composables/useEntryScene'
import AuthModal from '@/components/auth-modal/auth-modal.vue'
import EntrySections from '@/components/entry-sections/entry-sections.vue'
const version = ref(uni.$u.config.v)
const platform = ref(uni.getSystemInfoSync().uniPlatform)
const userStore = useUserStore()
/**
@ -118,7 +106,7 @@ const userStore = useUserStore()
*
* - **动态菜单段**(在前)= `user.info` 的 menus × `PAGE_REGISTRY`(如「外仓商品」分类),
* 登录后才有;未登录 / 拉取失败 / 后端未配时为空
* - **本地「工具」段**(固定在后)= `PageMeta.common === true` 的页面(计算器 / 条形码),
* - **本地「辅助工具」段**(固定在后)= `PageMeta.common === true` 的页面(计算器 / 条形码),
* 不看登录态、不看接口 ⇒ **未登录也一定显示**
* (微信审核要求:不能出现「需登录才能看到任何内容」)
*/

View File

@ -192,7 +192,7 @@ onLoad((options) => {
} catch {
code.value = raw
}
console.log('[confirm-login] 登录码 =', code.value)
// ⚠️ 登录码是「电脑端登录凭证」,任何环境都不打印
if (!code.value) failed.value = true
})

View File

@ -32,6 +32,32 @@
</up-cell-group>
</view>
<!--
协议与隐私:**不依赖登录**(tabBar 一级页常驻,未登录也能查阅)
—— 微信要求「以明显方式提示用户阅读隐私政策」,入口放在一级页最易达
-->
<view class="card">
<up-cell-group :border="false">
<up-cell
title="用户须知"
value="查看"
is-link
:border="false"
@click="openAgreement"
></up-cell>
<up-cell
title="隐私保护指引"
value="查看"
is-link
:border="false"
@click="openPrivacyContract"
></up-cell>
</up-cell-group>
</view>
<!-- 用户须知弹窗(只读;正文加载 / 富文本判定都在组件内部) -->
<agreement-modal v-model:show="agreementVisible" mode="view"></agreement-modal>
<!-- 登录抽屉:碰到需要登录的接口时自动弹出,也可由按钮主动唤起 -->
<auth-modal></auth-modal>
</view>
@ -46,7 +72,7 @@
* - 菜单里的细项(身份信息 / 待绑定 / 微信资料 / 电脑端登录码 / **退出登录**)全部移到
* 二级页 `pages/mine/user-info`,本页不再堆卡片
*
* ⚠️ 功能入口(九宫格)统一放在**首页** = 后端菜单分类段 + 本地「工具」段;
* ⚠️ 功能入口(九宫格)统一放在**首页** = 后端菜单分类段 + 本地「辅助工具」段;
* 本页不再渲染页面列表(2026-09-25 调整)。
*/
import { computed } from 'vue'
@ -57,6 +83,8 @@ import { getToken } from '@/utils/auth'
import { navigateToPath } from '@/utils/navigate'
import { getPageByKey } from '@/router/pages'
import AuthModal from '@/components/auth-modal/auth-modal.vue'
import AgreementModal from '@/components/agreement-modal/agreement-modal.vue'
import { useLegalLinks } from '@/composables/useLegalLinks'
/** 「用户信息」二级页的逻辑路径(物理路径从 PAGE_REGISTRY 取,避免两处漂移) */
const USER_INFO_KEY = '/mine/user-info'
@ -66,6 +94,9 @@ const userStore = useUserStore()
/** 本页是公共页面(auth: 'optional'),登录入口统一走 usePageAuth:登录**就地弹抽屉** */
const { goLogin } = usePageAuth('optional')
/** 协议与隐私入口(用户须知 / 官方隐私保护指引):一级页常驻,**不依赖登录** */
const { agreementVisible, openAgreement, openPrivacyContract } = useLegalLinks()
/** 微信头像(设置过才有,未设置时回退占位图标) */
const headimgurl = computed(() => userStore.headimgurl)

View File

@ -113,16 +113,10 @@
<view class="card__note">在电脑端登录页凭此登录码登录本账号</view>
</view>
<!-- ⑥ 用户须知(登录后也能随时查看;已登录时取当前仓库小程序的配置) -->
<view class="card">
<up-cell
title="用户须知"
value="查看"
is-link
:border="false"
@click="agreementVisible = true"
></up-cell>
</view>
<!--
用户须知 / 隐私保护指引:已移到「我的」页(一级页常驻,**未登录也能看**)——
本页在未登录时不可达,放这里会导致未登录用户根本找不到隐私入口。
-->
<!-- ⑤ 退出登录(从「我的」页移来:细项统一收在本页) -->
<view class="footer">
@ -217,12 +211,6 @@
</view>
</up-popup>
<!--
用户须知(**只读**模式:已登录后随时查看,不要求滑到底)
正文与滑到底判定都在组件内部;已登录时它会优先取「当前仓库小程序」的配置
-->
<agreement-modal v-model:show="agreementVisible" mode="view"></agreement-modal>
<!--
登录抽屉(登录入口)
⚠️ 硬约束:`usePageAuth.goLogin()` 是「**就地弹抽屉**」而不是跳页(见 `composables/usePageAuth.ts`),
@ -259,7 +247,6 @@ import { AVATAR_CANVAS_ID, avatarFileToPngBase64 } from '@/utils/avatar'
import WechatBindForm from '@/components/wechat-bind-form/wechat-bind-form.vue'
import EmptyState from '@/components/empty-state/empty-state.vue'
import AuthModal from '@/components/auth-modal/auth-modal.vue'
import AgreementModal from '@/components/agreement-modal/agreement-modal.vue'
const userStore = useUserStore()
@ -388,7 +375,12 @@ const closeProfileEditor = () => {
*/
const onChooseAvatar = async (event: { detail?: { avatarUrl?: string } }) => {
const tempPath = event?.detail?.avatarUrl || ''
if (!tempPath) return
if (!tempPath) {
// 取消选择不会触发本事件;能走到这里多半是**未在《隐私保护指引》声明「头像昵称」**
//(平台会直接禁用 chooseAvatar,返回空路径)→ 给一个可执行的提示,不要静默失败
uni.$u.toast('未获取到头像,如无法选择请在「…」→设置中同意隐私协议')
return
}
uni.showLoading({ title: '处理中', mask: true })
@ -470,17 +462,20 @@ const onShowLoginCode = async () => {
}
}
/** 复制登录码(微信自带「内容已复制」提示,这里不再重复 toast) */
/**
* 复制登录码(微信自带「内容已复制」提示,这里不再重复 toast)
*
* ⚠️ 复制属于隐私接口(官方清单里「读取你的剪切板」= wx.setClipboardData):
* 后台未声明或用户拒绝了隐私授权时这里会直接失败,必须给提示。
*/
const onCopyLoginCode = () => {
if (!loginCode.value) return
uni.setClipboardData({ data: loginCode.value })
uni.setClipboardData({
data: loginCode.value,
fail: () => uni.$u.toast('复制失败,请确认已同意《隐私保护指引》')
})
}
/* ───────────── ⑥ 用户须知 ───────────── */
/** 须知弹窗(只读);正文加载与滑到底判定都在 `agreement-modal` 内部 */
const agreementVisible = ref(false)
/* ───────────── ⑤ 退出登录 ───────────── */
/**

View File

@ -1,120 +0,0 @@
<template>
<view class="page">
<!-- required 未登录:页内「请先登录」+ 去登录,**不自动跳转** -->
<auth-gate auth="required">
<template #default>
<view class="card">
<view class="card__title">当前身份</view>
<up-cell-group :border="false">
<up-cell title="姓名" :value="userStore.userName || '-'" :border="false"></up-cell>
<up-cell title="身份类型" :value="userStore.roleTypeLabel || '-'" :border="false"></up-cell>
<up-cell title="所属组织" :value="userStore.currentEmployee?.store_name || '-'" :border="false"></up-cell>
</up-cell-group>
</view>
<view class="card">
<view class="card__title">按钮级权限示例</view>
<view class="text">用 checkPermission() 控制按钮显隐(示例权限点:store.getStoreRoles)。</view>
<view class="actions">
<up-button
v-if="canViewRoles"
type="primary"
shape="circle"
size="small"
text="有权限才显示的按钮"
@click="onGuardedTap"
></up-button>
<view v-else class="text text--warn">
当前账号没有 store.getStoreRoles 权限 → 按钮不渲染(这是预期行为,不是 bug)
</view>
</view>
</view>
<view class="card">
<view class="card__title">账号权限点(共 {{ userStore.permissions.length }} 个)</view>
<view v-if="!userStore.permissions.length" class="text">
接口未下发 permissions —— 可回头核对后端是否按端返回 type='api' 的权限点。
</view>
<view v-else class="text">
<view v-for="item in permissionPreview" :key="item" class="perm">{{ item }}</view>
<view v-if="userStore.permissions.length > permissionPreview.length" class="perm">
…共 {{ userStore.permissions.length }} 个
</view>
</view>
</view>
</template>
</auth-gate>
<!-- 登录抽屉:点「去登录」或碰需要登录的接口时就地弹出(不跳页) -->
<auth-modal></auth-modal>
</view>
</template>
<script setup lang="ts">
/**
* 框架示例页:`required`(需登录)
*
* 用途:验证「页内请先登录」体验 + 按钮级权限判断(`checkPermission`)。
*
* ⚠️ 这是「页面渲染框架」的示例页,业务页上线后可直接删除
* (删除时同步清理:pages.json 的 subPackages、PAGE_REGISTRY、condition)。
*/
import { computed } from 'vue'
import { useUserStore } from '@/store/modules/user'
import AuthModal from '@/components/auth-modal/auth-modal.vue'
const userStore = useUserStore()
/** 页面按钮级权限:无该权限时整块不渲染 */
const canViewRoles = computed(() => userStore.checkPermission('store.getStoreRoles'))
/** 权限点只展示前 20 个,避免页面被刷屏 */
const permissionPreview = computed(() => userStore.permissions.slice(0, 20))
const onGuardedTap = () => {
uni.$u.toast('有权限,按钮可点')
}
</script>
<style lang="scss" scoped>
.page {
min-height: 100vh;
background-color: #f5f6fa;
padding-top: 24rpx;
}
.card {
margin: 0 24rpx 24rpx;
padding: 8rpx 0;
background-color: #ffffff;
border-radius: 16rpx;
overflow: hidden;
&__title {
padding: 24rpx 32rpx 8rpx;
font-size: 30rpx;
font-weight: 600;
color: #303133;
}
}
.text {
padding: 8rpx 32rpx 16rpx;
font-size: 26rpx;
line-height: 1.7;
color: #606266;
&--warn {
color: #ff9900;
}
}
.perm {
font-size: 24rpx;
color: #909399;
}
.actions {
padding: 8rpx 32rpx 24rpx;
}
</style>

View File

@ -1,338 +0,0 @@
<template>
<view class="page">
<!-- 登录抽屉:点「去登录」或碰需要登录的接口时就地弹出(不跳页) -->
<auth-modal></auth-modal>
<auth-gate auth="required">
<template #default>
<view class="card">
<view class="card__title">页面信息</view>
<up-cell-group :border="false">
<up-cell title="逻辑路径" value="/test/index" :border="false"></up-cell>
<up-cell title="物理路径" value="pagesA/test/index" :border="false"></up-cell>
<up-cell title="后端数据源" value="wms_permission id=628" :border="false"></up-cell>
</up-cell-group>
</view>
<view class="card">
<view class="card__title">当前账号</view>
<up-cell-group :border="false">
<up-cell title="姓名" :value="userStore.userName || '-'" :border="false"></up-cell>
<up-cell title="身份类型" :value="userStore.roleTypeLabel || '-'" :border="false"></up-cell>
<up-cell
title="所属组织"
:value="userStore.currentEmployee?.store_name || '-'"
:border="false"
></up-cell>
<up-cell
title="权限点数"
:value="String(userStore.permissions.length)"
:border="false"
></up-cell>
</up-cell-group>
</view>
<view class="card">
<view class="card__title">
后端菜单(根节点 {{ permissionStore.menus.length }} 个)
</view>
<view v-if="!permissionStore.menus.length" class="text text--warn">
后端没有下发任何菜单 → 说明 platform=miniProgram 时 menus 未取自
miniprogram_pages,或当前账号的角色未授权 628。
</view>
<template v-else>
<view class="text">
下列 path 若包含 /test/index,说明后端已按 miniprogram_pages 下发。
</view>
<view v-for="item in menuPaths" :key="item" class="code">{{ item }}</view>
<view v-if="menuPaths.length >= 30" class="text">…(只显示前 30 条)</view>
</template>
</view>
<view class="card">
<view class="card__title">入口解析结果</view>
<up-cell-group :border="false">
<up-cell
title="可见入口数"
:value="String(permissionStore.leafCount)"
:border="false"
></up-cell>
<up-cell
title="未登记 key"
:value="permissionStore.missing.length ? `${permissionStore.missing.length} 个` : '无'"
:border="false"
></up-cell>
</up-cell-group>
<view v-if="permissionStore.missing.length" class="text text--warn">
以下 key 后端下发了但本地未登记(会被忽略):
</view>
<view v-for="item in permissionStore.missing.slice(0, 10)" :key="item" class="code">
{{ item }}
</view>
</view>
<view class="card">
<view class="card__title">身份 / token 诊断</view>
<up-cell-group :border="false">
<up-cell
title="user.info 身份ID"
:value="String(userStore.user.employees_id ?? '-')"
:border="false"
></up-cell>
<up-cell
title="user.info 身份名"
:value="String(userStore.user.employees_name ?? '-')"
:border="false"
></up-cell>
<up-cell
title="user.info 组织"
:value="String(userStore.user.store_name ?? '-')"
:border="false"
></up-cell>
<up-cell
title="user.info platform_code"
:value="String(userStore.user.platform_code ?? '-')"
:border="false"
></up-cell>
<up-cell
title="本地选中身份ID"
:value="String(userStore.currentEmployeeId || '-')"
:border="false"
></up-cell>
<up-cell
title="本地选中身份名"
:value="userStore.currentEmployee?.store_name || '-'"
:border="false"
></up-cell>
<up-cell
title="token 内存/存储"
:value="tokenSynced ? '一致' : '不一致 ⚠️'"
:border="false"
></up-cell>
<up-cell title="内存 token" :value="fingerprint(userStore.token)" :border="false"></up-cell>
<up-cell title="存储 token" :value="fingerprint(storedToken)" :border="false"></up-cell>
<up-cell
title="token.platform_code"
:value="payloadText('platform_code')"
:border="false"
></up-cell>
<up-cell
title="token.current_role_id"
:value="payloadText('current_role_id')"
:border="false"
></up-cell>
<up-cell
title="token.current_store_id"
:value="payloadText('current_store_id')"
:border="false"
></up-cell>
<up-cell title="token 过期时间" :value="expText" :border="false"></up-cell>
</up-cell-group>
<view class="text text--warn">
现象对照:① 「本地选中身份ID」≠「user.info 身份ID」→ 前端状态与服务端不同步;
② 「token.current_role_id」还是旧身份 → 新 token 没落地,
切换后重进小程序必然变回旧身份(后端按 (账号, platform_code) 记当前身份)。
</view>
<view class="actions">
<up-button
type="primary"
shape="circle"
size="small"
text="重拉 user.info"
@click="onReload"
></up-button>
</view>
</view>
<view v-if="logEnabled" class="card">
<view class="card__title">身份操作流水(最新在前)</view>
<view v-if="!identityLog.length" class="text">暂无记录</view>
<view v-for="(item, index) in identityLog" :key="index" class="log">
<view class="log__head">
<text class="log__time">{{ item.at }}</text>
<text class="log__event">{{ item.event }}</text>
</view>
<view v-if="item.detail" class="log__detail">{{ item.detail }}</view>
</view>
<view class="actions">
<up-button
type="primary"
:plain="true"
shape="circle"
size="small"
text="清空流水"
@click="onClearLog"
></up-button>
</view>
</view>
</template>
</auth-gate>
</view>
</template>
<script setup lang="ts">
/**
* 测试页 —— 验证「后端 miniprogram_pages → 首页动态菜单入口」整条链路
*
* 对应 `wms_permission` id = 628(type='miniprogram_pages',path='/test/index')。
* 已加入 `pages.json` 的 `condition`,微信开发者工具「编译模式」可直达。
*
* ⚠️ 这是链路验证页,验证完成后可删除
* (删除时同步清理:pages.json 的 subPackages / condition、PAGE_REGISTRY、以及数据库 628 行)。
*/
import { computed, ref } from 'vue'
import { onShow } from '@dcloudio/uni-app'
import { useUserStore } from '@/store/modules/user'
import AuthModal from '@/components/auth-modal/auth-modal.vue'
import { usePermissionStore } from '@/store/modules/permission'
import { getToken } from '@/utils/auth'
import { formatTokenTime, parseTokenPayload, tokenFingerprint } from '@/utils/token'
import { clearIdentityLog, IDENTITY_LOG_ENABLED, readIdentityLog } from '@/utils/identity-log'
import type { IdentityLogEntry } from '@/utils/identity-log'
import type { MenuNode } from '@/router/entries'
const userStore = useUserStore()
const permissionStore = usePermissionStore()
/* ───────── 身份 / token 诊断(用真实数据定位「切换身份后重进又变回旧身份」)───────── */
/** 存储里的 token(与内存副本对比,可看出新 token 是否真的落了地) */
const storedToken = ref(getToken())
const tokenSynced = computed(() => !!userStore.token && userStore.token === storedToken.value)
const tokenPayload = computed(() => parseTokenPayload(userStore.token || storedToken.value))
/** token payload 里的某个字段(缺值显示 `-`) */
const payloadText = (key: string): string => {
const value = tokenPayload.value?.[key]
return value === undefined || value === null ? '-' : String(value)
}
const expText = computed(() => formatTokenTime(tokenPayload.value?.exp))
const fingerprint = (token?: string): string => tokenFingerprint(token)
/** 重拉一次 user.info,对比服务端返回的身份 */
const onReload = (): void => {
storedToken.value = getToken()
identityLog.value = readIdentityLog()
userStore.getInfo(true).catch(() => {
// 失败提示由 request 层统一 toast
})
}
/* ───────── 身份操作流水(切换过程取证用,见 utils/identity-log.ts)───────── */
/** 总开关关闭时,卡片不渲染、读取恒为空(埋点调用保留在 store / App.vue 里) */
const logEnabled = IDENTITY_LOG_ENABLED
const identityLog = ref<IdentityLogEntry[]>(readIdentityLog())
const onClearLog = (): void => {
clearIdentityLog()
identityLog.value = []
uni.$u.toast('流水已清空')
}
// 每次进入本页重新读一次存储,避免看到上一轮的旧值
onShow(() => {
storedToken.value = getToken()
identityLog.value = readIdentityLog()
})
/** 把后端菜单树拍平成 path 列表(最多 30 条),便于直接核对 */
const menuPaths = computed<string[]>(() => {
const out: string[] = []
const walk = (nodes: MenuNode[]): void => {
for (const node of nodes) {
if (out.length >= 30) return
if (node.path) out.push(node.path)
const children = node.children
if (children && children.length) walk(children)
}
}
walk(permissionStore.menus)
return out
})
</script>
<style lang="scss" scoped>
.page {
min-height: 100vh;
background-color: #f5f6fa;
padding-top: 24rpx;
}
.card {
margin: 0 24rpx 24rpx;
padding: 8rpx 0;
background-color: #ffffff;
border-radius: 16rpx;
overflow: hidden;
&__title {
padding: 24rpx 32rpx 8rpx;
font-size: 30rpx;
font-weight: 600;
color: #303133;
}
}
.text {
padding: 8rpx 32rpx 16rpx;
font-size: 26rpx;
line-height: 1.7;
color: #606266;
&--warn {
color: #ff9900;
}
}
.code {
margin: 0 32rpx 8rpx;
padding: 6rpx 16rpx;
font-size: 24rpx;
color: #2979ff;
background-color: #f2f6ff;
border-radius: 6rpx;
word-break: break-all;
}
/* 「重拉 user.info」等卡片内按钮 */
.actions {
padding: 8rpx 32rpx 24rpx;
}
/* 身份操作流水 */
.log {
padding: 12rpx 32rpx;
border-bottom: 1rpx solid #f2f3f5;
&__head {
display: flex;
align-items: center;
}
&__time {
margin-right: 12rpx;
font-size: 24rpx;
color: #909399;
}
&__event {
font-size: 26rpx;
font-weight: 600;
color: #303133;
}
&__detail {
margin-top: 4rpx;
font-size: 22rpx;
line-height: 1.6;
color: #606266;
word-break: break-all;
}
}
</style>

View File

@ -29,16 +29,6 @@
@click="copyContent"
></up-button>
</view>
<view class="actions__item">
<up-button
:plain="true"
type="primary"
shape="circle"
size="small"
text="示例"
@click="useSample"
></up-button>
</view>
<view class="actions__item">
<up-button
:plain="true"
@ -139,12 +129,11 @@ const QUIET_MODULES = 10
const MODULE_PREFERRED = 2
const MODULE_MAX = 4
/** 初始给一个示例,进页面即可看到效果(可一键清空) */
const SAMPLE = 'WMS-20261014'
/** 输入内容:**默认空**(不预填示例,避免页面一进来就出现假单号) */
const content = ref('')
const content = ref(SAMPLE)
const windowWidth = uni.getSystemInfoSync().windowWidth || 375
// 窗口宽度:用 getWindowInfo(`getSystemInfoSync` 已被官方标注「不再维护」)
const windowWidth = uni.getWindowInfo().windowWidth || 375
/** rpx → px:本条码的宽度计算**必须用 px**(条空宽度要是整数像素) */
const rpx2px = (value: number): number => (value * windowWidth) / 750
/** 可用宽度 = 屏宽 −(页面左右 24rpx + 卡片左右 32rpx) */
@ -209,14 +198,11 @@ function copyContent(): void {
uni.setClipboardData({
data: text,
fail: () => uni.$u.toast('复制失败')
// 剪切板是隐私接口(官方清单「读取你的剪切板」):未声明/未同意时会直接失败
fail: () => uni.$u.toast('复制失败,请确认已同意《隐私保护指引》')
})
}
function useSample(): void {
content.value = SAMPLE
}
function reset(): void {
content.value = ''
}

View File

@ -364,7 +364,8 @@ function copyResult(): void {
uni.setClipboardData({
data: text,
fail: () => uni.$u.toast('复制失败')
// 剪切板是隐私接口(官方清单「读取你的剪切板」):未声明/未同意时会直接失败
fail: () => uni.$u.toast('复制失败,请确认已同意《隐私保护指引》')
})
}
</script>

View File

@ -11,7 +11,7 @@
* | 未命中 | **忽略该项**,记入 `missing`(不影响其它入口,由调用方告警) |
* | 分组节点无子项命中 | 整组丢弃(避免渲染出空分组) |
* | `hidden = 1` | 不进导航入口 |
* | `common: true` 的本地页面 | 无论后端是否下发,都进首页「工具」段(见 `LOCAL_COMMON_ENTRIES`) |
* | `common: true` 的本地页面 | 无论后端是否下发,都进首页「辅助工具」段(见 `LOCAL_COMMON_ENTRIES`) |
*
* ⚠️ **输出固定为两层**(`EntryGroup.children` 只能是 `EntryLeaf`):
* 小程序首页是「分组标题 + 子项九宫格」(决策点 4),
@ -184,7 +184,7 @@ export function generateEntries(menus: MenuNode[] | null | undefined): GenerateE
}
/**
* 首页「工具」—— **本地维护**的页面列表(与后端菜单无关)
* 首页「辅助工具」—— **本地维护**的页面列表(与后端菜单无关)
*
* 为什么单独搞一份:这个段要在**任何登录态 / 授权 / 接口故障 / 后端未配置**的情况下都稳定,
* 用来常驻放「必须有」或「随时要进」的页面(公开工具页关系到微信审核)。
@ -269,23 +269,23 @@ export function toSections(nodes: EntryNode[], options: ToSectionsOptions = {}):
return sections
}
/** 首页本地「工具」段的段标题(= `PageMeta.common` 选出来的那一组) */
export const TOOLS_SECTION_TITLE = '工具'
/** 首页本地「辅助工具」段的段标题(= `PageMeta.common` 选出来的那一组) */
export const TOOLS_SECTION_TITLE = '辅助工具'
/**
* 首页入口分段 = **动态菜单段** + **本地「工具」段**
* 首页入口分段 = **动态菜单段** + **本地「辅助工具」段**
*
* 顺序(2026-10-14 定):**动态菜单段在前、「工具」段固定在后** ——
* 顺序(2026-10-14 定):**动态菜单段在前、「辅助工具」段固定在后** ——
* 业务功能随角色 / 权限变化,是首页主体;工具是固定入口,放最后不抢视线。
*
* 形态完全一致(都是「标题 + 子项九宫格」),差别只在来源:
* 前者由 `user.info` 的 `menus` 驱动,后者前端写死。
*
* - **「工具」段无论是否登录都渲染**(纯本地清单、不看接口)⇒ 未登录时首页也一定有内容,
* - **「辅助工具」段无论是否登录都渲染**(纯本地清单、不看接口)⇒ 未登录时首页也一定有内容,
* 这正是微信审核「不能出现需登录才能看到任何内容」的落点
* - **去重**:本地段里已有的 key 会从动态段中剔除
* (后端也配了同一个页面时,只在「工具」段出现一次)
* - 动态段为空(未登录 / 后端没配 / 拉取失败)时,结果就是纯粹的「工具」段
* (后端也配了同一个页面时,只在「辅助工具」段出现一次)
* - 动态段为空(未登录 / 后端没配 / 拉取失败)时,结果就是纯粹的「辅助工具」段
*/
export function toHomeSections(
nodes: EntryNode[],
@ -302,7 +302,7 @@ export function toHomeSections(
sections.push({ ...section, leaves })
}
// ② 本地「工具」段:固定最后、固定存在
// ② 本地「辅助工具」段:固定最后、固定存在
if (LOCAL_COMMON_ENTRIES.length) {
sections.push({ key: 'tools', title: TOOLS_SECTION_TITLE, leaves: LOCAL_COMMON_ENTRIES })
}

View File

@ -42,13 +42,13 @@ export interface PageMeta {
/** 是否不进导航入口(九宫格 / 功能菜单):可被跳转,但不作为入口展示 */
hidden?: boolean
/**
* 是否进首页**本地**「工具」列表
* 是否进首页**本地**「辅助工具」列表
*
* - **必须显式写 `common: true` 才会进**(不设置 = 不进)
* - 该列表在 `router/entries.ts` 的 `LOCAL_COMMON_ENTRIES`,**与后端菜单无关**:
* 不受登录态 / 授权 / 接口故障 / 后端是否配置影响 → 「无论是否登录都会显示」
* - 后端 `miniprogram_pages` 只负责「登录后**还**能看到什么」,
* 在首页以**分类段**(如「外仓商品」)排在「工具」段**前面**;两处重复的 key 会自动去重
* 在首页以**分类段**(如「外仓商品」)排在「辅助工具」段**前面**;两处重复的 key 会自动去重
*
* ⚠️ `auth: 'public'` 的页面请一并标 `common: true` —— 否则未登录时首页会没有任何入口
*(微信审核要求「不能需登录才能看到任何内容」)
@ -107,9 +107,9 @@ export const PAGE_REGISTRY: PageMeta[] = [
hidden: true
},
// ─────────────── 工具(分包 pagesA):首页「工具」段,**不登录也能用** ───────────────
// ─────────────── 辅助工具(分包 pagesA):首页「辅助工具」段,**不登录也能用** ───────────────
// ⚠️ 这两页是「未登录也要有可浏览内容」这条微信审核要求的落点:
// 标了 `common: true` ⇒ 常驻首页「工具」段(不受登录态 / 后端菜单 / 接口故障影响),
// 标了 `common: true` ⇒ 常驻首页「辅助工具」段(不受登录态 / 后端菜单 / 接口故障影响),
// 位置固定在**动态菜单段之后**(见 entries.ts 的 `toHomeSections`)。
{
key: '/tools/calculator',
@ -128,31 +128,13 @@ export const PAGE_REGISTRY: PageMeta[] = [
common: true
},
// ──────── 框架示例页(分包 pagesA):验证三态渲染与权限,业务页上线后可删 ────────
{
key: '/demo/required',
path: 'pagesA/demo/required',
title: '需登录示例',
icon: 'lock',
auth: 'required',
// 需登录的页不进公共入口;登录后由后端菜单下发才出现在九宫格
hidden: true
},
{
key: '/test/index',
path: 'pagesA/test/index',
title: '测试页',
icon: 'grid',
auth: 'required',
// 2026-10-14 起**不在首页展示**,两处一起堵:
// - 去掉 `common: true` → 不再进本地「工具」段
// - 加 `hidden: true` → 后端菜单(wms_permission id=628)下发了也不渲染入口
// (只去掉 common 不够:登录后仍会由后端菜单那一侧冒出来)
// 需要联调时:微信开发者工具「编译模式」选「测试页」直接进(pages.json 的 condition 已保留)
hidden: true
},
// ─────────────── 业务页(分包)───────────────
// ⚠️ 调试页已**彻底删除**(2026-10-17):
// `/demo/required`(需登录示例)与 `/test/index`(身份 / token 诊断页)——
// 页面文件、`pages.json`(含 `condition`)与 `PAGE_REGISTRY` 登记全部移除
// (提审自检要求「移除测试入口页」)。
// 今后若再需要临时诊断页:新建 .vue → 登记 `pages.json` + 这里 → 跑 `check:pages`,
// 并在**提审前**再次摘除(诊断页会显示身份 / 权限点 / token 指纹,不能上线)。
{
key: '/external-stock/list',
path: 'pagesA/external-stock/list',
@ -161,7 +143,7 @@ export const PAGE_REGISTRY: PageMeta[] = [
auth: 'required'
// ⚠️ 后端 wms_permission 里这条记录的 path(type='miniprogram_pages')
// 必须与上面的 key **逐字符相等**,否则入口会被忽略并进 permissionStore.missing
// 未设 common → 不进本地「工具」(它属于后端菜单那一侧)
// 未设 common → 不进本地「辅助工具」(它属于后端菜单那一侧)
// 不设 hidden → 登录后由后端菜单下发才出现,首页以「外仓商品」**分类段**展示
},
{
@ -172,7 +154,7 @@ export const PAGE_REGISTRY: PageMeta[] = [
auth: 'required'
// 对应后端 id=642(父节点 641「外部仓库」分类,2026-10-14 新增)—— 同样必须与 key 逐字符相等
// 不设 hidden → 登录后由后端菜单下发才出现(未授权该页 id 的角色看不到)
// 未设 common → 不进本地「工具」(它属于后端菜单那一侧)
// 未设 common → 不进本地「辅助工具」(它属于后端菜单那一侧)
// 接口 storeWarehouse.warehouse.list(**货主侧**,与 new3 views/warehouses 同源),
// 见 api/warehouse/external-warehouse.ts
},

View File

@ -19,6 +19,7 @@
import { getPageByKey } from '@/router/pages'
import { navigateToPath } from '@/utils/navigate'
import { debugLog } from '@/utils/debug-log'
import type { EntryInfo } from '@/utils/entry'
/** 场景处理函数签名 */
@ -80,14 +81,8 @@ export async function handleEntryScene(entry: EntryInfo): Promise<void> {
return
}
console.log(
`[entry] ${scene.name}:code =`,
entry.code,
'| userId =',
entry.userId,
'| extra =',
entry.extra
)
// ⚠️ 不打印 code / userId:前者是登录码(电脑端登录凭证),后者是用户标识
debugLog(`[entry] ${scene.name}`, { hasCode: Boolean(entry.code) })
await scene.handle(entry)
}

16
src/shims-wx.d.ts vendored
View File

@ -5,7 +5,8 @@
* `@dcloudio/types` 的 `uni-app/uni-patches/wx/index.d.ts` 只声明了 `UniNamespace`
* 命名空间,**未**在编译单元内声明全局 `wx`,因此 uni-app 项目里直接写 `wx.xxx`
* 会报 `TS2304: Cannot find name 'wx'`。
* 这里按需声明本项目用到的原生 API(目前只有 `wx.getAccountInfoSync`)。
* 这里按需声明本项目用到的原生 API(目前:`wx.getAccountInfoSync`、`wx.exitMiniProgram`、
* `wx.openPrivacyContract`)。
*
* 后续若原生调用变多,建议安装 `miniprogram-api-typings` 并加入 tsconfig 的 `types`,
* 然后删除本文件。
@ -45,4 +46,17 @@ declare const wx: {
fail?: () => void
complete?: () => void
}): void
/**
* 打开《小程序用户隐私保护指引》页面(基础库 2.32.3+)
*
* 内容由公众平台后台「设置 → 服务内容声明 → 用户隐私保护指引」配置,
* 不是小程序自己的页面 —— 用户可随时复查隐私条款。
* @see https://developers.weixin.qq.com/miniprogram/dev/api/open-api/privacy/wx.openPrivacyContract.html
*/
openPrivacyContract(options?: {
success?: () => void
fail?: () => void
complete?: () => void
}): void
}

9
src/sitemap.json Normal file
View File

@ -0,0 +1,9 @@
{
"desc": "内部仓储管理系统(WMS):页面属于登录后的业务操作界面,不需要被微信搜索索引",
"rules": [
{
"action": "disallow",
"page": "*"
}
]
}

View File

@ -52,7 +52,9 @@ export const usePermissionStore = defineStore('permission', {
/**
* 用 `user.info` 的 menus 重建入口树
*
* 后端 `miniprogram_pages` 已开始配置(测试页 628 + 外仓商品分类 630 / 页面 631):
* 后端 `miniprogram_pages` 现状(2026-10-17 实查 `wms.wms_permission`):
* 分类 630「外仓商品」+ 页面 631;分类 632「外仓库存」+ 633/637/638/639;
* 分类 641「外部仓库」+ 642 —— **没有任何测试页记录**(原 id=628 已删除)。
* 命中本地 `PAGE_REGISTRY` 的项成为入口,未命中的进 `missing`(只告警不报错)。
* 若当前角色未授权这些节点,`entries` 会是空数组,这是**预期行为**:
* UI 回退到本地公共入口 + 空态文案,不报错。

View File

@ -12,6 +12,7 @@
import { defineStore } from 'pinia'
import { getLoginChannel, getToken, removeToken, setLoginChannel, setToken } from '@/utils/auth'
import { appendIdentityLog } from '@/utils/identity-log'
import { debugLog } from '@/utils/debug-log'
import { parseTokenPayload, tokenFingerprint } from '@/utils/token'
import type { LoginChannel } from '@/utils/auth'
import {
@ -330,18 +331,14 @@ export const useUserStore = defineStore('user', {
*/
async wechatBind(payload: { username: string; password: string }): Promise<void> {
const current = getToken()
// 调试日志:确认「请求带了 token」(绑定失败最常见的原因是登录态丢了)
console.log('[wechat] bindUser 发起', {
username: payload.username.trim(),
hasToken: !!current,
tokenHead: current ? `${current.slice(0, 20)}...` : '(空)'
})
// 只记「有没有带 token」:username / token / 用户对象都是敏感信息,不打日志
debugLog('[wechat] bindUser 发起', { hasToken: !!current })
const resp = await apiWechatBindUser({
username: payload.username.trim(),
password: payload.password
})
console.log('[wechat] bindUser 返回', { flag: resp.flag, code: resp.code, user: resp.data?.user })
debugLog('[wechat] bindUser 返回', { flag: resp.flag, code: resp.code })
const token = resp.data?.token || ''
if (!token) {

22
src/utils/debug-log.ts Normal file
View File

@ -0,0 +1,22 @@
/**
* 开发期日志(生产构建自动失效)
*
* 为什么要这层封装:
* 1. `console.log` 会原样打进线上包,真机开调试模式就能看到 ——
* 里面一旦带**登录码 / token / 用户信息**就是信息泄露(安全风险,不是"代码不干净"那么简单)
* 2. 提审自检要求「移除调试代码 / console.log」,但排查问题又确实需要它
*
* 做法:只在 **开发态** 输出。Vite 在构建时会把 `import.meta.env.DEV` 折叠成常量,
* 生产包里这个分支直接消失(可用 `dist/build/mp-weixin/utils/debug-log.js` 验证)。
*
* ⚠️ 约定(比"用不用 debugLog"更重要):
* - **登录码 / token / 密码 / 完整用户对象** —— 连 `debugLog` 都不许打印,直接删
* - `console.warn` / `console.error` 保留:只用于异常诊断,同样不得带上述敏感数据
*/
/** 开发期日志:仅 `import.meta.env.DEV` 为真时输出 */
export function debugLog(...args: unknown[]): void {
if (import.meta.env.DEV) {
console.log(...args)
}
}

View File

@ -9,7 +9,8 @@
* ## 开 / 关
* 把 `IDENTITY_LOG_ENABLED` 改成 `true` 即可启用:
* - store / App.vue 里的 `appendIdentityLog(...)` 调用**一直都在**(关闭时只是空转),无需改它们
* - 测试页会自动出现「身份操作流水」卡(同一个开关控制)
* - 需要展示时调 `readIdentityLog()`(最新在前)——原先的测试页已于 2026-10-17 删除,
* 临时排查可新建一个页面/卡片直接渲染它
*
* 2026-09-26 首轮使用完毕(当时定位了后端 `user.changeRole` 写库正确但 token 用旧身份的缺陷,
* 后端已修复)⇒ 先关闭,不启用;以后再排查身份 / 菜单 / 权限类问题时再打开。
@ -19,7 +20,7 @@
* ⇒ 「退出登录 → 重新登录」以及「重进小程序」之后,仍然能看到切换前后的全过程
* 2. **只记关键字段**(身份 id / store / token 指纹),**绝不记完整 token**(凭证不进日志/截图)
*
* 清空入口:测试页「身份操作流水」卡的「清空流水」按钮,或开发者工具「清除数据缓存」。
* 清空入口:`clearIdentityLog()`,或开发者工具「清除数据缓存」。
*/
/** 总开关:`false` = 不记录、不展示(埋点调用保留,空转) */

View File

@ -19,15 +19,14 @@
*
* 开发者工具中若项目未填 AppID,这里会拿到 `touristappid`(调用方按「拿不到」处理即可)。
*/
import { debugLog } from '@/utils/debug-log'
export function getMiniProgramAppid(): string {
let appid = ''
// #ifdef MP-WEIXIN
try {
const accountInfo = wx.getAccountInfoSync()
// 调试输出:在微信开发者工具控制台核对运行时真实 AppID
// (重点看 miniProgram.appId;envVersion=develop/trial/release 可确认当前环境)
console.log('[wechat] wx.getAccountInfoSync() =', accountInfo)
console.log('[wechat] 小程序 AppID =', accountInfo.miniProgram.appId, '环境 =', accountInfo.miniProgram.envVersion)
// 开发期日志:核对运行时真实 AppID 与环境(生产构建自动失效,见 utils/debug-log)
debugLog('[wechat] 小程序 AppID =', accountInfo.miniProgram.appId, '环境 =', accountInfo.miniProgram.envVersion)
appid = accountInfo.miniProgram.appId || ''
} catch (err) {

View File

@ -23,21 +23,21 @@
| 分包(pages.json 注册) | 🚧 部分注册 | `pagesA` 已注册(当前放框架示例页);`pagesB` / `pagesC` 待业务页一起注册 |
| 请求封装(第 5 节) | ✅ 已完成 | `utils/request.ts`,对齐 new3,含 token 注入 / 响应头续期 / 401 处理 |
| 登录鉴权(第 6 节) | ✅ 已完成 | 账号密码登录 + 注册;登录入口在「我的」页头部(启动页为首页,不强制登录);401 按需引导登录 |
| 「我的」页结构 | ✅ 已完成(2026-09-22) | **菜单 + 二级页面**:本页只留「登录入口 + 菜单」;细项全收进 `pages/mine/user-info`(用户信息 / 待绑定 WMS 账号 / 微信资料 / 电脑端登录码 / 退出登录) |
| 「我的」页结构 | ✅ 已完成(2026-09-22,10-17 增协议入口) | **菜单 + 二级页面**:本页只留「登录入口 + 菜单 + 协议与隐私」;细项全收进 `pages/mine/user-info`(用户信息 / 待绑定 WMS 账号 / 微信资料 / 电脑端登录码 / 退出登录)。<br>⚠️ 用户须知 / 隐私保护指引 **不依赖登录**,所以不能放二级页(未登录进不去),统一放本页 |
| Pinia 状态管理(第 8 节) | ✅ 已完成 | `pinia@2.1.7`(Vue 3.4 兼容版),见 `store/modules/user.ts` |
| 环境变量(第 11 节) | ✅ 已完成 | `.env.development` / `.env.production`:`VITE_APP_BASE_API` / `VITE_APP_PLATFORM` / `VITE_APP_PROJECT` |
| 静态路由表(阶段 1) | ✅ 已完成 | `src/router/pages.ts`:`PAGE_REGISTRY`(逻辑路径 → 物理页面 + `auth` 策略)+ `PAGE_MAP`;配置 `npm run check:pages` 一致性校验 |
| 菜单/权限 store(阶段 2) | ✅ 已完成 | `src/router/entries.ts`(菜单 × 路由表 → 入口树)+ `store/modules/permission.ts`;`getInfo()` 触发时机收口到「登录成功 / 启动带 token / 切换身份」 |
| 三态渲染组件(阶段 3) | ✅ 已完成 | `composables/usePageAuth.ts` + `components/auth-gate/`(public / optional / required)+ `components/empty-state/`(统一空态文案 + 重试);「去登录」收口到 `goLogin()` |
| 页面接入(阶段 4) | ✅ 已完成 | 首页九宫格改为 store 驱动(分组标题 + 子项两层渲染,空态走 `empty-state`);「我的」新增功能菜单 |
| 首页入口分段(2026-10-14) | ✅ 已完成 | **动态菜单段(在前)+ 本地「工具」段(固定在后)**,合成逻辑在 `router/entries.ts` 的 `toHomeSections()`;「工具」段 = `common: true` 的页面(计算器 / 条形码),**与登录态、后端菜单、接口无关 ⇒ 未登录也一定显示**(微信审核要求)。已删除原 `pagesA/demo/public.vue`(被计算器页取代) |
| 首页入口分段(2026-10-14,段名 10-17 改为「辅助工具」) | ✅ 已完成 | **动态菜单段(在前)+ 本地「辅助工具」段(固定在后)**,合成逻辑在 `router/entries.ts` 的 `toHomeSections()`;「辅助工具」段 = `common: true` 的页面(计算器 / 条形码),**与登录态、后端菜单、接口无关 ⇒ 未登录也一定显示**(微信审核要求)。已删除原 `pagesA/demo/public.vue`(被计算器页取代) |
| 页面渲染框架 | 🚧 开发中(阶段 1、2、2.5、3、4 已完成) | 见第 12 节与《页面渲染框架-设计与任务清单.md》 |
| 身份(角色/仓库)展示 | ✅ 已完成 | 「我的」页登录后显示:姓名 / 身份类型 / 所属组织 / 员工 ID / 授权到期;数据来自 `user.info` 的 `employees[]`,**不改数据库** |
| 身份切换 `changeRole` | 🚧 已实现待联调 | 入口在「我的」页(多身份时出现);接口已实测存在,返回结构待后端确认 |
| 微信一键登录 | ✅ 已完成 | `wechat.loginByCode`(不是 `user.loginByCode`);AppID 运行时取(`wx.getAccountInfoSync`,适配开放平台模板多仓库);token 立即落地(未绑定也算免登录态);绑定可跳过、入口常驻「我的」页 |
| 微信资料(昵称/头像) | ✅ 已完成(2026-09-22) | `wechat.updateInfo`(改昵称)+ `wechat.uploadHeadimg`(传头像);走微信「头像昵称填写能力」(`chooseAvatar` + `input type=nickname`),头像经 `utils/avatar.ts` 裁剪转 PNG(<500K)后上传;入口仅未绑定态可见 |
| 我的登录码(电脑端登录) | ✅ 已完成(2026-09-22) | `wechat.getMyLoginCode`(无入参,码**稳定不变**);入口在「我的」页(需微信登录态);同时新增登录渠道记录 `login_channel` |
| 用户须知(协议文案) | ✅ 已完成(2026-09-23) | 弹窗抽为共享组件 `components/agreement-modal/`(`agree` 勾选 / `view` 只读);入口两处:登录面板勾选区 + 「用户信息」页;正文后端下发(免登录按 AppID / 已登录按仓库),本地常量仅兵底 |
| 用户须知(协议文案) | ✅ 已完成(2026-09-23) | 弹窗抽为共享组件 `components/agreement-modal/`(`agree` 勾选 / `view` 只读);入口两处:登录面板勾选区 + **「我的」页**(2026-10-17 由「用户信息」页移来,因为未登录时二级页不可达);正文后端下发(免登录按 AppID / 已登录按仓库),本地常量仅兜底 |
> 📄 **配套文档**:`页面渲染框架-设计与任务清单.md` —— 菜单 / 权限 / 页面渲染的决策与任务清单(第 12 节为摘要)
> ⚠️ **已知坑**:同时跑两个 `dev:mp-weixin` 进程会写坏产物,导致预览报
@ -103,9 +103,12 @@
- [x] **`transformPx` 保持 `false`** ✅
该选项已废弃,仅部分平台生效,新项目不推荐开启(当前已是 `false`,保持即可)。
- [ ] **(暂缓)配置 `sitemap.json`**
不配置时微信使用默认索引规则(收录全部页面)。
内部仓储工具通常不需要被微信搜索收录,故暂缓;若需禁止收录或精细控制,再补该文件。
- [x] **配置 `sitemap.json`** ✅ 2026-10-17
`src/sitemap.json`(构建后原样拷到产物根目录,已实测)→ 全部页面 `disallow`:
内部仓储工具不应被微信搜索收录,也避免业务页面被外部检索到。
```json
{ "rules": [{ "action": "disallow", "page": "*" }] }
```
- [x] **不要提交个人调试配置** ✅
微信开发者工具会在打开的产物目录生成 `project.private.config.json`;
@ -153,15 +156,17 @@ d:\wechat\
│ ├── auth-guard.ts # 登录跳转(LOGIN_PAGE / redirectToLogin,不做全局拦截)
│ ├── barcode.ts # Code128(B) 编码(输出条空宽度序列,供工具页渲染)
│ ├── calculator.ts # 四则运算求值(自写解析器,不用 eval)
│ ├── debug-log.ts # 开发期日志(生产构建自动空转)
│ ├── navigate.ts # 统一跳转(自动区分 switchTab / navigateTo)
│ └── request.ts # uni.request 封装
├── pages/ # 主包页面(启动页 + tabBar 页)
│ ├── login/login.vue # 登录 / 注册页(非启动页,仅 401 兜底 / 直接访问)
│ ├── index/index.vue # 首页(启动页):动态菜单段 + 本地「工具」段
│ ├── index/index.vue # 首页(启动页):动态菜单段 + 本地「辅助工具」段
│ └── mine/mine.vue # 我的
├── sitemap.json # 禁止微信搜索索引(全部 disallow)
├── pagesA/ # 分包 A(已注册)
│ ├── tools/ # 计算器 / 条形码(公共工具页,`common: true` → 首页「工具」段)
│ └── demo/ # required.vue(需登录 + 按钮级权限示例)
│ ├── tools/ # 计算器 / 条形码(公共工具页,`common: true` → 首页「辅助工具」段)
│ └── external-*/ # 业务页(外仓商品 / 外部仓库 / 收货单 / 库存报表 / 入库单 / 商品流水)
├── pagesB/ # 分包 B(规划:出库,待注册)
├── pagesC/ # 分包 C(规划:库存/盘点,待注册)
└── static/ # 静态资源
@ -480,13 +485,24 @@ d:\wechat\
## 7. 权限与隐私合规(提审重点)
- [ ] **梳理隐私接口清单**
涉及定位、相册、摄像头、麦克风、剪贴板、通讯录、蓝牙等的 API 需逐一确认。
仓储场景重点:**扫码(摄像头)、上传图片(相册/相机)、定位(如库位导航)、蓝牙打印**。
- [x] **梳理隐私接口清单** ✅ 2026-10-17
全仓搜索确认**实际只用两个**隐私能力(其余定位/相册/相机/麦克风/通讯录/蓝牙/手机号均未使用,
`manifest` 也没有 `permission` / `requiredPrivateInfos`,与实际一致):
- [ ] **配置《小程序用户隐私保护指引》**
微信公众平台 → 设置 → 基本设置 → 服务内容声明 → 用户隐私保护指引,声明实际收集的信息类型。
未声明而调用隐私接口,会在真机上被拦截。
| 用到的能力 | 代码位置 | 官方清单归属 |
|---|---|---|
| `<button open-type="chooseAvatar">` + `<input type="nickname">` | `pages/mine/user-info.vue` | **收集你的昵称、头像** |
| `uni.setClipboardData`(复制登录码 / 计算结果 / 条码内容) | `user-info.vue`、`tools/calculator.vue`、`tools/barcode.vue` | **读取你的剪切板**(官方清单把 `setClipboardData` 也归在这里) |
- [ ] **配置《小程序用户隐私保护指引》(平台后台,必须做)**
微信公众平台 → 设置 → 服务内容声明 → 用户隐私保护指引,**至少勾选**:
1. 「收集你的昵称、头像」(否则 `chooseAvatar` 被禁用 → 点头像无反应、`input type=nickname` 降级为普通输入框)
2. 「读取你的剪切板」(否则 3 处复制全部失败,报 `errno 112 / api scope is not declared`)
> 补充声明 5 分钟后生效。未声明不是「体验差」而是**接口直接不可用**。
> 代码侧已提供入口:「我的」页 → 「隐私保护指引」→ `wx.openPrivacyContract()`(条件编译 MP-WEIXIN,
> 逻辑收口在 `composables/useLegalLinks.ts`;该入口**不依赖登录**)。
> 项目未接 `wx.onNeedPrivacyAuthorization`,依赖微信 2023-10-17 后强制的官方隐私弹窗;
> 用户拒绝时 3 处复制会失败并提示「请确认已同意《隐私保护指引》」。
- [ ] **处理授权被拒的分支**
用户拒绝授权后应有降级方案与引导(引导至 `uni.openSetting` 重新开启),不能白屏或静默失败。
@ -508,6 +524,14 @@ d:\wechat\
- [ ] **尺寸单位统一用 `rpx`**(750 设计稿基准);`manifest.json` 的 `transformPx` 保持 `false`,不要依赖 px 自动转换。
- [x] **不做深色模式(浅色主题锁)** ✅ 2026-10-17
本项目配色全部写死为浅色(`#f5f6fa` 底 / `#ffffff` 卡片 / `#303133` 文字),**不做深色适配**。
但 uview-plus 会跟随系统深色模式把文字变白、弹层变黑(白底白字),所以做了三件事:
1. `main.ts` → `uni.$u.setThemePreference('light')`(管 JS 算出来的颜色:弹层背景 / 输入框文字)
2. `App.vue` 全局 `page { --up-* / --up-light-* }` 钉回浅色原值(管 CSS 变量驱动的颜色,如 `up-cell`)
3. `manifest.json → mp-weixin.darkmode = false`(产物 `app.json` 已含,原生导航栏/ tabBar 不变深)
> 若将来真要支持深色:改 `darkmode: true` + 配置 `themeLocation`,并逐页改造写死的颜色(工作量大,不建议半做)。
- [ ] **品牌色与主题变量集中管理**
在 `src/uni.scss` 中覆盖 uview-plus 的 `$u-*` 变量(`theme.scss` 内变量均为 `!default`,放在文件末尾即可覆盖)。
⚠️ 严禁把 `uview-plus/index.scss` 引入 `uni.scss`(会破坏按需引入并导致包体积暴涨),它只能写在 `App.vue`。
@ -584,11 +608,17 @@ d:\wechat\
## 10. 发布上线流程
- [ ] **上传前自检**
- `setting.minified` 已开启、`urlCheck` 已恢复校验
- 已切换到正式环境接口地址与正式 AppID
- 已移除调试代码、`console.log`、测试入口页
- 主包/分包体积均未越线
- [x] **上传前自检(代码侧已就绪 2026-10-17)**
- ✅ 已**删除**测试入口页:`pagesA/test/index.vue`(含 628 诊断页数据)与 `pagesA/demo/required.vue`
均已删除,并同步清理 `pages.json`(含 `condition`)/ `PAGE_REGISTRY`;
产物 `pagesA` 只剩 `tools` + 业务页
- ✅ `console.log` 已收口到 `utils/debug-log.ts`(生产构建空转,产物已验证为 `function(){}`);
**登录码 / token / 用户对象一律不打印**(`confirm-login`、`bindUser`、入口场景均已清理)
- ✅ `sitemap.json` 已配置(全部 `disallow`)
- ⬜ 仍需手动:`manifest.json → mp-weixin.setting.urlCheck` 改回 `true`(本地联调要连局域网
接口,平时保持 `false`;该项只影响开发者工具校验,**不影响上传包**)
- ⬜ 仍需手动:切换正式环境接口地址 / 正式 AppID
- ✅ 包体积:主包 ≈ 0.44MB、总计 ≈ 0.54MB(限额 2MB / 20MB)
- [ ] **版本管理**
`manifest.json` → `versionName`(如 1.0.0)/ `versionCode`(递增整数)
@ -828,7 +858,8 @@ I --> J["PC / 工作台轮询取回 → 登录为该账号"]
- [x] 文案改为**后端下发**(2026-09-23),本地常量降为**兜底**:
- 弹窗抽为**共享组件** `components/agreement-modal/`,两种模式:
`mode="agree"`(登录前勾选,**必须滑到底**才能同意)/ `mode="view"`(已登录后只读查看,不要求滑动)
- 两个入口:① 登录面板的协议勾选区;② **「用户信息」页的「用户须知」行**(已登录也能随时查看)
- 两个入口:① 登录面板的协议勾选区;② **「我的」页的「用户须知」/「隐私保护指引」行**
(2026-10-17 从「用户信息」页移来:一级页常驻、**未登录也能查阅**,合规更稳)
- 主链路:`wechat.getUserAgreementText({ appId })` —— **免登录**,按当前小程序运行时 AppID 取;
登录抽屉里就要看须知(此时未登录),所以必须走这条
- 已**业务登录**时优先:`wechat.getUserAgreement` —— 按登录仓库取启用小程序,另带小程序昵称;