自营商家和合作商家入口分开,添加智能柜角色切换
This commit is contained in:
1 parent
e34cc2736c
commit
1a74921af9
5 files changed
+119
-96
No files matched your search
+57
-53
@@ -1,6 +1,7 @@
|
||||
<script lang="ts">
|
||||
import isDevEnv from "./sheep/utils/isDevEnv"
|
||||
import { getAppInfo } from "@@/utils/getAppInfo"
|
||||
import getLaunchParam from "@/sheep/utils/getLaunchParam"
|
||||
|
||||
// import { onLaunch, onShow, onHide } from "@dcloudio/uni-app"
|
||||
// onLaunch(() => {})
|
||||
@@ -38,7 +39,7 @@ const tabbar: TabbarItem[] = [
|
||||
text: "合作商家",
|
||||
iconPath: "/static/tabbar/coopMerchant.png",
|
||||
selectedIconPath: "/static/tabbar/coopMerchant-select.png",
|
||||
launchParam: ["selfMerchant"],
|
||||
launchParam: ["coopMerchant"],
|
||||
auth: ["user"],
|
||||
},
|
||||
{
|
||||
@@ -47,14 +48,14 @@ const tabbar: TabbarItem[] = [
|
||||
iconPath: "/static/tabbar/cabinet.png",
|
||||
selectedIconPath: "/static/tabbar/cabinet-select.png",
|
||||
launchParam: [],
|
||||
auth: ["cabinetAdmin"],
|
||||
auth: ["doorAdmin"],
|
||||
},
|
||||
{
|
||||
pagePath: "pages/tabbar/order",
|
||||
text: "订单",
|
||||
iconPath: "/static/tabbar/order.png",
|
||||
selectedIconPath: "/static/tabbar/order-select.png",
|
||||
launchParam: ["canteen", "selfMerchant"],
|
||||
launchParam: ["canteen", "selfMerchant", "coopMerchant"],
|
||||
auth: ["user"],
|
||||
},
|
||||
{
|
||||
@@ -79,15 +80,10 @@ const tabbar: TabbarItem[] = [
|
||||
iconPath: "/static/tabbar/my.png",
|
||||
selectedIconPath: "/static/tabbar/my-select.png",
|
||||
launchParam: ["canteen", "selfMerchant", "coopMerchant"],
|
||||
auth: ["user", "merchant"],
|
||||
auth: ["user", "merchant", "doorAdmin"],
|
||||
},
|
||||
]
|
||||
|
||||
// 获取启动参数
|
||||
const getLaunchParam = () => {
|
||||
return new URL(window.location.href).searchParams.get("launchParam")
|
||||
}
|
||||
|
||||
// 设置tabbar项目
|
||||
const setTabbarItem = (index: number, item: TabbarItem, visible: boolean) => {
|
||||
uni.setTabBarItem({
|
||||
@@ -101,28 +97,26 @@ const setTabbarItem = (index: number, item: TabbarItem, visible: boolean) => {
|
||||
}
|
||||
|
||||
// 根据启动参数设置tabbar项目
|
||||
const setTabbarByLaunchParam = (launchParam: string) => {
|
||||
tabbar.forEach((item, index) => {
|
||||
const visible = item.launchParam.includes(launchParam)
|
||||
setTabbarItem(index, item, visible)
|
||||
})
|
||||
}
|
||||
|
||||
// 根据用户角色设置tabbar项目
|
||||
const setTabbarByUserRole = (role: string) => {
|
||||
tabbar.forEach((item, index) => {
|
||||
let visible = false
|
||||
if (item.auth.includes("cabinetAdmin")) {
|
||||
if (uni.getStorageSync("isHardDoorAdmin") == "true") {
|
||||
visible = true
|
||||
} else {
|
||||
visible = false
|
||||
}
|
||||
} else {
|
||||
visible = item.auth.includes(role)
|
||||
}
|
||||
setTabbarItem(index, item, visible)
|
||||
})
|
||||
const setTabbar = (launchParam?: string, auth?: string) => {
|
||||
if (launchParam && !auth) {
|
||||
tabbar.forEach((item, index) => {
|
||||
const visible = item.launchParam.includes(launchParam)
|
||||
setTabbarItem(index, item, visible)
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!launchParam && auth) {
|
||||
tabbar.forEach((item, index) => {
|
||||
const visible = item.auth.includes(auth)
|
||||
setTabbarItem(index, item, visible)
|
||||
})
|
||||
}
|
||||
if (launchParam && auth) {
|
||||
tabbar.forEach((item, index) => {
|
||||
const visible = item.launchParam.includes(launchParam) && item.auth.includes(auth)
|
||||
setTabbarItem(index, item, visible)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
@@ -135,17 +129,16 @@ export default {
|
||||
const appInfo = await getAppInfo()
|
||||
if (appInfo == "zzd") {
|
||||
// 浙政钉环境
|
||||
const launchParam = getLaunchParam()
|
||||
|
||||
console.log("app launch 启动路径参数", launchParam)
|
||||
|
||||
switch (launchParam) {
|
||||
switch (getLaunchParam()) {
|
||||
case "canteen":
|
||||
uni.switchTab({ url: "/pages/tabbar/canteen" })
|
||||
break
|
||||
case "selfMerchant":
|
||||
uni.switchTab({ url: "/pages/tabbar/selfMerchant" })
|
||||
break
|
||||
case "coopMerchant":
|
||||
uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
|
||||
break
|
||||
default:
|
||||
break
|
||||
}
|
||||
@@ -156,7 +149,10 @@ export default {
|
||||
case "merchant":
|
||||
return uni.switchTab({ url: "/pages/tabbar/individualOrder" })
|
||||
case "user":
|
||||
return uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
|
||||
if (getLaunchParam() === "selfMerchant") return uni.switchTab({ url: "/pages/tabbar/selfMerchant" })
|
||||
if (getLaunchParam() === "coopMerchant") return uni.reLaunch({ url: "/pages/tabbar/coopMerchant" })
|
||||
case "doorAdmin":
|
||||
return uni.switchTab({ url: "/pages/tabbar/cabinet" })
|
||||
default:
|
||||
return uni.redirectTo({ url: "/pages/user/userRole" })
|
||||
}
|
||||
@@ -175,13 +171,12 @@ export default {
|
||||
}
|
||||
|
||||
const launchParam = getLaunchParam()
|
||||
console.log("tabbar launch 启动路径参数", launchParam)
|
||||
|
||||
const appInfo = await getAppInfo()
|
||||
if (appInfo == "zzd") {
|
||||
// 浙政钉环境
|
||||
if (launchParam) {
|
||||
setTabbarByLaunchParam(launchParam)
|
||||
setTabbar(launchParam)
|
||||
uni.showTabBar()
|
||||
} else {
|
||||
uni.hideTabBar()
|
||||
@@ -190,20 +185,29 @@ export default {
|
||||
} else if (appInfo == "sh") {
|
||||
// 是诗画环境
|
||||
const userRole = uni.getStorageSync("userRole")
|
||||
switch (userRole) {
|
||||
case "user":
|
||||
setTabbarByUserRole("user")
|
||||
uni.showTabBar()
|
||||
break
|
||||
case "merchant":
|
||||
setTabbarByUserRole("merchant")
|
||||
uni.showTabBar()
|
||||
break
|
||||
default:
|
||||
uni.hideTabBar()
|
||||
uni.removeStorageSync("userRole")
|
||||
uni.showToast({ title: "用户身份未确认", icon: "none" })
|
||||
break
|
||||
if (launchParam) {
|
||||
switch (userRole) {
|
||||
case "user":
|
||||
setTabbar(launchParam, "user")
|
||||
uni.showTabBar()
|
||||
break
|
||||
case "merchant":
|
||||
setTabbar(undefined, "merchant")
|
||||
uni.showTabBar()
|
||||
break
|
||||
case "doorAdmin":
|
||||
setTabbar(undefined, "doorAdmin")
|
||||
uni.showTabBar()
|
||||
break
|
||||
default:
|
||||
uni.hideTabBar()
|
||||
uni.removeStorageSync("userRole")
|
||||
uni.showToast({ title: "用户身份未确认", icon: "none" })
|
||||
break
|
||||
}
|
||||
} else {
|
||||
uni.hideTabBar()
|
||||
uni.showToast({ title: "启动参数不合法", icon: "none" })
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -3,11 +3,12 @@ import { ref, reactive } from "vue"
|
||||
import { onLoad, onShow } from "@dcloudio/uni-app"
|
||||
|
||||
import { hooks, router } from "@@/index"
|
||||
import { orderApi, payApi } from "@@/api"
|
||||
import { orderApi } from "@@/api"
|
||||
|
||||
import { filePath } from "@@/utils/file"
|
||||
|
||||
import zTabs from "@@/components/other/z-tabs/z-tabs.vue"
|
||||
import getLaunchParam from "@/sheep/utils/getLaunchParam"
|
||||
|
||||
const data = {
|
||||
tabs: [
|
||||
@@ -44,9 +45,11 @@ const doTab = (e: any) => {
|
||||
const pageRef = ref<any>(null)
|
||||
const pageHook = hooks.usePage(
|
||||
pageRef,
|
||||
new URL(window.location.href).searchParams.get("launchParam") == "canteen"
|
||||
getLaunchParam() == "canteen"
|
||||
? orderApi.caneenPage
|
||||
: new URL(window.location.href).searchParams.get("launchParam") == "selfMerchant"
|
||||
: getLaunchParam() == "selfMerchant"
|
||||
? orderApi.supPage
|
||||
: getLaunchParam() == "coopMerchant"
|
||||
? orderApi.supPage
|
||||
: async () => [],
|
||||
null,
|
||||
|
||||
+49
-40
@@ -4,7 +4,7 @@
|
||||
<view class="main-text-40 mb-2">请选择您的身份</view>
|
||||
</view>
|
||||
|
||||
<view class="px-6 my-20">
|
||||
<view class="px-6">
|
||||
<view
|
||||
class="card mb-6 overflow-hidden relative border-8 border-solid border-white duration-200"
|
||||
:class="{ 'border-8 border-solid border-blue!': userRole === 'user' }"
|
||||
@@ -19,7 +19,7 @@
|
||||
</view>
|
||||
|
||||
<view
|
||||
class="card overflow-hidden relative border-8 border-solid border-white duration-200"
|
||||
class="card mb-6 overflow-hidden relative border-8 border-solid border-white duration-200"
|
||||
:class="{ 'border-8 border-solid border-blue!': userRole === 'merchant' }"
|
||||
@click="selectRole('merchant')"
|
||||
>
|
||||
@@ -30,6 +30,19 @@
|
||||
<view class="main-text-32 mb-1">我是商户</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view
|
||||
class="card overflow-hidden relative border-8 border-solid border-white duration-200"
|
||||
:class="{ 'border-8 border-solid border-blue!': userRole === 'doorAdmin' }"
|
||||
@click="selectRole('doorAdmin')"
|
||||
>
|
||||
<view class="flex-row items-center p-6">
|
||||
<view class="w-64 h-64 rounded-full flex-col-center mr-8">
|
||||
<image src="@/static/page/doorAdminRole.svg" />
|
||||
</view>
|
||||
<view class="main-text-32 mb-1">我是智能柜管理员</view>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="flex-row-center px-10 mt-auto pb-10 font-bold">
|
||||
@@ -39,56 +52,52 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { userApi } from "@/sheep/api"
|
||||
import { ref } from "vue"
|
||||
import { userApi } from "@/sheep/api"
|
||||
import getLaunchParam from "@/sheep/utils/getLaunchParam"
|
||||
|
||||
const userRole = ref("user")
|
||||
|
||||
const selectRole = (role: "user" | "merchant") => (userRole.value = role)
|
||||
const selectRole = (role: "user" | "merchant" | "doorAdmin") => (userRole.value = role)
|
||||
|
||||
// 确认选择
|
||||
const confirmRole = async () => {
|
||||
if (userRole.value === "user") {
|
||||
uni.showLoading({ title: "正在验证身份", mask: true })
|
||||
const res: any = await userApi.userRole().finally(() => uni.hideLoading())
|
||||
if (res.code == 0) {
|
||||
if (res.data.isHardDoorAdmin) {
|
||||
uni.setStorageSync("userRole", userRole.value)
|
||||
uni.setStorageSync("isHardDoorAdmin", "true")
|
||||
uni.reLaunch({ url: "/pages/tabbar/coopMerchant" })
|
||||
return
|
||||
} else {
|
||||
uni.setStorageSync("userRole", userRole.value)
|
||||
uni.setStorageSync("isHardDoorAdmin", "false")
|
||||
uni.reLaunch({ url: "/pages/tabbar/coopMerchant" })
|
||||
return
|
||||
}
|
||||
} else {
|
||||
switch (userRole.value) {
|
||||
case "user":
|
||||
uni.setStorageSync("userRole", userRole.value)
|
||||
uni.setStorageSync("isHardDoorAdmin", "false")
|
||||
uni.reLaunch({ url: "/pages/tabbar/coopMerchant" })
|
||||
return
|
||||
}
|
||||
}
|
||||
if (userRole.value === "merchant") {
|
||||
uni.showLoading({ title: "正在验证身份", mask: true })
|
||||
const res: any = await userApi.userRole().finally(() => uni.hideLoading())
|
||||
if (res.code == 0) {
|
||||
if (res.data.isMch) {
|
||||
uni.setStorageSync("userRole", userRole.value)
|
||||
if (res.data.isHardDoorAdmin) {
|
||||
uni.setStorageSync("isHardDoorAdmin", "true")
|
||||
if (getLaunchParam() === "selfMerchant") return uni.reLaunch({ url: "/pages/tabbar/selfMerchant" })
|
||||
if (getLaunchParam() === "coopMerchant") return uni.reLaunch({ url: "/pages/tabbar/coopMerchant" })
|
||||
break
|
||||
case "merchant":
|
||||
uni.showLoading({ title: "正在验证身份", mask: true })
|
||||
const res1: any = await userApi.userRole().finally(() => uni.hideLoading())
|
||||
if (res1.code == 0) {
|
||||
if (res1.data.isMch) {
|
||||
uni.setStorageSync("userRole", userRole.value)
|
||||
uni.reLaunch({ url: "/pages/tabbar/individualOrder" })
|
||||
} else {
|
||||
uni.setStorageSync("isHardDoorAdmin", "false")
|
||||
uni.showToast({ title: "您不是商户", icon: "none" })
|
||||
}
|
||||
uni.reLaunch({ url: "/pages/tabbar/individualOrder" })
|
||||
return
|
||||
} else {
|
||||
uni.showToast({ title: "您不是商户", icon: "none" })
|
||||
uni.showToast({ title: "身份验证失败", icon: "none" })
|
||||
}
|
||||
} else {
|
||||
uni.showToast({ title: "身份验证失败", icon: "none" })
|
||||
}
|
||||
break
|
||||
case "doorAdmin":
|
||||
uni.showLoading({ title: "正在验证身份", mask: true })
|
||||
const res2: any = await userApi.userRole().finally(() => uni.hideLoading())
|
||||
if (res2.code == 0) {
|
||||
if (res2.data.isHardDoorAdmin) {
|
||||
uni.setStorageSync("userRole", userRole.value)
|
||||
uni.reLaunch({ url: "/pages/tabbar/cabinet" })
|
||||
} else {
|
||||
uni.showToast({ title: "您不是智能柜管理员", icon: "none" })
|
||||
}
|
||||
} else {
|
||||
uni.showToast({ title: "身份验证失败", icon: "none" })
|
||||
}
|
||||
break
|
||||
default:
|
||||
uni.showToast({ title: "请选择您的身份", icon: "none" })
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,6 @@
|
||||
// 获取启动参数
|
||||
const getLaunchParam = (): "canteen" | "selfMerchant" | "coopMerchant" | null => {
|
||||
return new URL(window.location.href).searchParams.get("launchParam") as "canteen" | "selfMerchant" | "coopMerchant" | null
|
||||
}
|
||||
|
||||
export default getLaunchParam
|
||||
@@ -0,0 +1 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg t="1745315220266" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="3915" data-spm-anchor-id="a313x.search_index.0.i2.114e3a81xJ17Of" xmlns:xlink="http://www.w3.org/1999/xlink" width="200" height="200"><path d="M791.551175 0.003021H198.656924C118.273161-0.508978 53.249353 64.51483 52.737355 144.386595V819.200604c0 79.871764 65.023808 144.895573 144.895572 144.895573h3.071991v24.575927c0 19.455943 15.871953 35.327896 35.327896 35.327896h2.559993c19.455943 0 35.327896-15.871953 35.327895-35.327896v-24.575927h475.646597v24.575927c0 19.455943 15.871953 35.327896 35.327896 35.327896h2.559992c19.455943 0 35.327896-15.871953 35.327896-35.327896v-24.575927h3.071991c79.871764 0 144.895573-65.023808 144.895573-144.895573V179.714491c0-99.327707-80.383763-179.71147-179.199472-179.71147zM129.537128 819.200604V144.898593c0-37.887888 30.719909-68.095799 68.095799-68.095799h275.967186v811.005608H197.632927c-37.37589-0.511998-68.095799-30.719909-68.095799-68.607798z m764.925744 0c0 37.887888-30.719909 68.607798-68.095799 68.607798h-275.967186V76.290796h241.151288c56.831832 0 102.911696 46.079864 102.911697 102.911696v639.998112z" p-id="3916" data-spm-anchor-id="a313x.search_index.0.i3.114e3a81xJ17Of" class="" fill="#505873"></path><path d="M364.544435 371.201926h2.559992c23.551931 0 35.327896 11.775965 35.327896 35.327896v66.047805c0 23.551931-11.775965 35.327896-35.327896 35.327895h-2.559992c-23.551931 0-35.327896-11.775965-35.327896-35.327895V406.529822c0-23.551931 11.775965-35.327896 35.327896-35.327896zM657.407571 371.201926h2.559992c23.551931 0 35.327896 11.775965 35.327896 35.327896v66.047805c0 23.551931-11.775965 35.327896-35.327896 35.327895h-2.559992c-23.551931 0-35.327896-11.775965-35.327896-35.327895V406.529822c-0.511998-23.551931 11.263967-35.327896 35.327896-35.327896z" fill="#FF402A" p-id="3917" data-spm-anchor-id="a313x.search_index.0.i6.114e3a81xJ17Of" class=""></path></svg>
|
||||
|
After Width: | Height: | Size: 2.0 KiB |
Reference in new issue
Block a user