From 64636d0eab6b5d8932d8ff927a17b51ddf9b01bf Mon Sep 17 00:00:00 2001 From: weiwei Date: Tue, 1 Apr 2025 14:19:11 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=97=E7=94=BB=E7=94=A8=E6=88=B7=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E8=BA=AB=E4=BB=BD=E9=80=89=E6=8B=A9=E5=92=8Ctabbar?= =?UTF-8?q?=E6=8E=A7=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 241 +++++++++++++++++++------------ src/pages.json | 25 ++-- src/pages/tabbar/userRole.vue | 3 - src/pages/user/userRole.vue | 54 +++++++ src/static/page/merchantRole.svg | 33 +++++ src/static/page/userRole.svg | 21 +++ 6 files changed, 270 insertions(+), 107 deletions(-) delete mode 100644 src/pages/tabbar/userRole.vue create mode 100644 src/pages/user/userRole.vue create mode 100644 src/static/page/merchantRole.svg create mode 100644 src/static/page/userRole.svg diff --git a/src/App.vue b/src/App.vue index 9f0d742..d9dc173 100644 --- a/src/App.vue +++ b/src/App.vue @@ -6,7 +6,6 @@ import isDevEnv from "./sheep/utils/isDevEnv" // onShow(() => {}) // onHide(() => {}) -// zhezhengding:浙政钉 | shihua:诗画 const tabbar = [ { pagePath: "pages/tabbar/canteen", @@ -14,7 +13,7 @@ const tabbar = [ iconPath: "/static/tabbar/canteen.png", selectedIconPath: "/static/tabbar/canteen-select.png", authPath: ["pages/tabbar/canteen"], - auth: ["zhezhengding"], + auth: [], }, { pagePath: "pages/tabbar/selfMerchant", @@ -22,7 +21,7 @@ const tabbar = [ iconPath: "/static/tabbar/selfMerchant.png", selectedIconPath: "/static/tabbar/selfMerchant-select.png", authPath: ["pages/tabbar/selfMerchant"], - auth: ["zhezhengding"], + auth: [], }, { pagePath: "pages/tabbar/coopMerchant", @@ -30,7 +29,7 @@ const tabbar = [ iconPath: "/static/tabbar/coopMerchant.png", selectedIconPath: "/static/tabbar/coopMerchant-select.png", authPath: ["pages/tabbar/selfMerchant"], - auth: ["zhezhengding"], + auth: ["user"], }, { pagePath: "pages/tabbar/order", @@ -38,7 +37,7 @@ const tabbar = [ iconPath: "/static/tabbar/order.png", selectedIconPath: "/static/tabbar/order-select.png", authPath: ["pages/tabbar/canteen", "pages/tabbar/selfMerchant"], - auth: ["zhezhengding"], + auth: ["user"], }, { pagePath: "pages/tabbar/flowStatistics", @@ -46,7 +45,7 @@ const tabbar = [ iconPath: "/static/tabbar/order.png", selectedIconPath: "/static/tabbar/order-select.png", authPath: [], - auth: [], + auth: ["merchant"], }, { pagePath: "pages/tabbar/individualOrder", @@ -54,7 +53,7 @@ const tabbar = [ iconPath: "/static/tabbar/order.png", selectedIconPath: "/static/tabbar/order-select.png", authPath: [], - auth: [], + auth: ["merchant"], }, { pagePath: "pages/tabbar/my", @@ -62,112 +61,172 @@ const tabbar = [ iconPath: "/static/tabbar/my.png", selectedIconPath: "/static/tabbar/my-select.png", authPath: ["pages/tabbar/canteen", "pages/tabbar/selfMerchant"], - auth: ["zhezhengding"], + auth: ["user", "merchant"], }, ] export default { onLaunch() { console.log("环境判断") - // ;(window as any).CP2.getUserInfo().then((res) => { - // console.log(res) - // if (res.code == 0) { - // uni.showToast({ title: res.msg || "当前环境不支持", icon: "none" }) - // } - // }) - - const launchParam = new URL(window.location.href).searchParams.get("launchParam") - console.log("app launch 启动路径参数", launchParam) - switch (launchParam) { - case "canteen": - uni.switchTab({ url: "/pages/tabbar/canteen" }) - break - case "selfMerchant": - uni.switchTab({ url: "/pages/tabbar/selfMerchant" }) - break - default: - break - } + // 诗画浦江获取用户信息进行环境判断 + ;(window as any).CP2.getUserInfo().then((res) => { + if (res.code !== 0) { + // 不是诗画环境 + const launchParam = new URL(window.location.href).searchParams.get("launchParam") + console.log("app launch 启动路径参数", launchParam) + switch (launchParam) { + case "canteen": + uni.switchTab({ url: "/pages/tabbar/canteen" }) + break + case "selfMerchant": + uni.switchTab({ url: "/pages/tabbar/selfMerchant" }) + break + default: + break + } + } else { + // 是诗画环境 + return uni.redirectTo({ url: "/pages/user/userRole" }) + } + }) }, onShow() {}, onHide() {}, methods: { _initTabbar() { - // console.log("环境判断") - // let appEnv = 1 // 1:浙政钉 2:诗画 - // const launchPath = uni.getLaunchOptionsSync().path // console.log("启动路径", launchPath) const launchParam = new URL(window.location.href).searchParams.get("launchParam") console.log("tabbar launch 启动路径参数", launchParam) - if (isDevEnv()) { - tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => { - uni.setTabBarItem({ - index, - pagePath, - text, - iconPath, - selectedIconPath, - visible: true, - }) - }) - } else { - switch (launchParam) { - case "canteen": - tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath }, index) => { - if (authPath.includes("pages/tabbar/canteen")) { - uni.setTabBarItem({ - index, - pagePath, - text, - iconPath, - selectedIconPath, - visible: true, - }) - } else { - uni.setTabBarItem({ - index, - pagePath, - text, - iconPath, - selectedIconPath, - visible: false, - }) - } + // 诗画浦江获取用户信息进行环境判断 + ;(window as any).CP2.getUserInfo().then((res) => { + if (res.code !== 0) { + // 不是诗画环境 + if (isDevEnv()) { + tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: true, + }) }) - break - case "selfMerchant": - tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath }, index) => { - if (authPath.includes("pages/tabbar/selfMerchant")) { - uni.setTabBarItem({ - index, - pagePath, - text, - iconPath, - selectedIconPath, - visible: true, + } else { + switch (launchParam) { + case "canteen": + tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath }, index) => { + if (authPath.includes("pages/tabbar/canteen")) { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: true, + }) + } else { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: false, + }) + } }) - } else { - uni.setTabBarItem({ - index, - pagePath, - text, - iconPath, - selectedIconPath, - visible: false, + break + case "selfMerchant": + tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath }, index) => { + if (authPath.includes("pages/tabbar/selfMerchant")) { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: true, + }) + } else { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: false, + }) + } }) - } - }) - break - default: - uni.hideTabBar() - uni.showToast({ title: "启动参数不合法", icon: "none" }) - break + break + default: + uni.hideTabBar() + uni.showToast({ title: "启动参数不合法", icon: "none" }) + break + } + } + } else { + // 是诗画环境 + const userRole = uni.getStorageSync("userRole") + switch (userRole) { + case "user": + tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => { + if (auth.includes("user")) { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: true, + }) + } else { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: false, + }) + } + }) + break + case "merchant": + tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => { + if (auth.includes("merchant")) { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: true, + }) + } else { + uni.setTabBarItem({ + index, + pagePath, + text, + iconPath, + selectedIconPath, + visible: false, + }) + } + }) + break + default: + uni.hideTabBar() + uni.showToast({ title: "用户身份未确认", icon: "none" }) + break + } } - } + }) }, }, } diff --git a/src/pages.json b/src/pages.json index 191b91e..b193088 100644 --- a/src/pages.json +++ b/src/pages.json @@ -9,13 +9,6 @@ } }, "pages": [ - // { - // "path": "pages/tabbar/userRole", - // "style": { - // "navigationBarTitleText": "用户角色", - // "disableScroll": true - // } - // }, { "path": "pages/tabbar/canteen", "style": { @@ -292,6 +285,18 @@ } ] }, + { + "root": "pages/user", + "pages": [ + { + "path": "userRole", + "style": { + "navigationBarTitleText": "用户身份", + "disableScroll": true + } + } + ] + }, { "root": "pages/pay", "pages": [ @@ -321,12 +326,6 @@ }, "tabBar": { "list": [ - // { - // "pagePath": "pages/tabbar/userRole", - // "text": "", - // "iconPath": "", - // "selectedIconPath": "" - // }, { "pagePath": "pages/tabbar/canteen", "text": "", diff --git a/src/pages/tabbar/userRole.vue b/src/pages/tabbar/userRole.vue deleted file mode 100644 index bf91dd0..0000000 --- a/src/pages/tabbar/userRole.vue +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/pages/user/userRole.vue b/src/pages/user/userRole.vue new file mode 100644 index 0000000..5e096cc --- /dev/null +++ b/src/pages/user/userRole.vue @@ -0,0 +1,54 @@ + + + diff --git a/src/static/page/merchantRole.svg b/src/static/page/merchantRole.svg new file mode 100644 index 0000000..0ec265d --- /dev/null +++ b/src/static/page/merchantRole.svg @@ -0,0 +1,33 @@ + + + + + + + + \ No newline at end of file diff --git a/src/static/page/userRole.svg b/src/static/page/userRole.svg new file mode 100644 index 0000000..613b7b4 --- /dev/null +++ b/src/static/page/userRole.svg @@ -0,0 +1,21 @@ + + + + \ No newline at end of file