接口修改
This commit is contained in:
1 parent
4452435ecf
commit
7ba2bfce2b
5 files changed
+6022
-4833
No files matched your search
+66
-37
@@ -9,51 +9,80 @@ import { hooks, router, constant } from "@@/index"
|
||||
import { merchantApi, userApi, walletApi } from "@@/api"
|
||||
import isDevEnv from "@/sheep/utils/isDevEnv"
|
||||
|
||||
const data = {
|
||||
serviceList: [
|
||||
{ text: "钱包管理", icon: "/static/icon/service_3.png", router: "/pages/wallet/list" },
|
||||
{ text: "包厢预定", icon: "/static/icon/service_4.png", router: "/pages/boxes/apply-list" },
|
||||
{ text: "外来人员就餐", icon: "/static/icon/service_1.png", router: "/pages/apply/foreign-list" },
|
||||
{ text: "跨单位就餐", icon: "/static/icon/service_1.png", router: "/pages/apply/stride-list" },
|
||||
{ text: "人脸管理", icon: "/static/icon/service_5.png", router: "/pages/human-face/list" },
|
||||
],
|
||||
// 定义类型
|
||||
interface ServiceItem {
|
||||
text: string
|
||||
icon: string
|
||||
router: string
|
||||
}
|
||||
|
||||
// 服务列表配置
|
||||
const DEFAULT_SERVICES: ServiceItem[] = [
|
||||
{ text: "钱包管理", icon: "/static/icon/service_3.png", router: "/pages/wallet/list" },
|
||||
{ text: "包厢预定", icon: "/static/icon/service_4.png", router: "/pages/boxes/apply-list" },
|
||||
{ text: "外来人员就餐", icon: "/static/icon/service_1.png", router: "/pages/apply/foreign-list" },
|
||||
{ text: "跨单位就餐", icon: "/static/icon/service_1.png", router: "/pages/apply/stride-list" },
|
||||
{ text: "人脸管理", icon: "/static/icon/service_5.png", router: "/pages/human-face/list" },
|
||||
]
|
||||
|
||||
// 状态管理
|
||||
const state = reactive<any>({
|
||||
wallet: [],
|
||||
userInfo: {},
|
||||
serviceList: [...DEFAULT_SERVICES],
|
||||
})
|
||||
|
||||
// 开发环境可以账号密码登录,生产环境不可
|
||||
const checkAppInfo = () => {
|
||||
;(window as any).CP2.getAppInfo().then((res) => {
|
||||
if (res.code == 1) {
|
||||
//诗画
|
||||
console.log("诗画环境")
|
||||
;(window as any).CP2.getUserInfo().then((res) => {
|
||||
let accountId = res.data.accountId
|
||||
let sessionId = res.sessionId
|
||||
doLogin(1, null, accountId, sessionId)
|
||||
})
|
||||
} else {
|
||||
console.log("浙政钉或者h5环境")
|
||||
const url = window.location.href
|
||||
const params = new URL(url).searchParams
|
||||
const token = params.get("uabaseToken") // 获取 uabaseToken 参数值
|
||||
// const token =
|
||||
// "eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6IjJiZGQzODE1LWFlMWYtNDFmZi04MTE2LTU3OWVkMjY3MDI5OCJ9.nuCBrYAkGh5-FG8S_ZTe8mcVVORAuUT7bl0qUIspL9gCNtwtcae2D6DhOO8Q2RtVhuFO5IKtOQ65Xd2Vd7pAUg"
|
||||
console.log("uabaseToken:", token)
|
||||
if (null != token) {
|
||||
//浙政钉
|
||||
doLogin(2, token, null, null)
|
||||
}
|
||||
// 登录相关方法
|
||||
const loginMethods = {
|
||||
// 诗画环境登录
|
||||
async shihuaLogin() {
|
||||
const appInfo = await (window as any).CP2.getAppInfo()
|
||||
if (appInfo.code !== 1) return false
|
||||
|
||||
const userInfo = await (window as any).CP2.getUserInfo()
|
||||
const { accountId, sessionId } = userInfo.data
|
||||
return doLogin(1, null, accountId, sessionId)
|
||||
},
|
||||
|
||||
// 浙政钉登录
|
||||
zhengdingLogin() {
|
||||
const params = new URL(window.location.href).searchParams
|
||||
const token = params.get("uabaseToken")
|
||||
if (token) {
|
||||
return doLogin(2, token, null, null)
|
||||
}
|
||||
})
|
||||
return false
|
||||
},
|
||||
}
|
||||
|
||||
onLoad((options) => {
|
||||
// 检查应用环境并登录
|
||||
const checkAppInfo = async () => {
|
||||
try {
|
||||
// 先尝试诗画登录
|
||||
const shihuaResult = await loginMethods.shihuaLogin()
|
||||
if (shihuaResult) return
|
||||
|
||||
// 尝试浙政钉登录
|
||||
const zhengdingResult = await loginMethods.zhengdingLogin()
|
||||
if (zhengdingResult) return
|
||||
|
||||
// 开发环境下跳转到测试登录页
|
||||
if (isDevEnv()) {
|
||||
router.jump("/pages/test/login")
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("登录失败:", error)
|
||||
uni.showToast({ title: "登录失败", icon: "none" })
|
||||
}
|
||||
}
|
||||
|
||||
onLoad(() => {
|
||||
if (isDevEnv()) {
|
||||
data.serviceList.push({ text: "测试登录", icon: "/static/icon/login.png", router: "/pages/test/login" })
|
||||
state.serviceList.push({
|
||||
text: "测试登录",
|
||||
icon: "/static/icon/login.png",
|
||||
router: "/pages/test/login",
|
||||
})
|
||||
}
|
||||
checkAppInfo()
|
||||
})
|
||||
@@ -125,7 +154,7 @@ const doLogin = async (loginType, token, accountId, sessionId) => {
|
||||
uni.setStorageSync(userInfoKey, userData)
|
||||
getUserInfo()
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: "登录成功", icon: "none" })
|
||||
// uni.showToast({ title: "登录成功", icon: "none" })
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({ title: "登录失败", icon: "none" })
|
||||
@@ -134,7 +163,7 @@ const doLogin = async (loginType, token, accountId, sessionId) => {
|
||||
}
|
||||
|
||||
const toService = async (v: any, i: number) => {
|
||||
if (i == data.serviceList.length - 1) {
|
||||
if (i == state.serviceList.length - 1) {
|
||||
router.jump(v.router)
|
||||
return
|
||||
}
|
||||
@@ -195,7 +224,7 @@ const onTabLogin = () => {
|
||||
<view class="m-t-40rpx rounded-20rpx shadow-main p-30rpx p-b-40rpx bg-white!">
|
||||
<view
|
||||
class="service_item flex-row items-center justify-between"
|
||||
v-for="(v, i) in data.serviceList"
|
||||
v-for="(v, i) in state.serviceList"
|
||||
:key="i"
|
||||
@tap="toService(v, i)"
|
||||
>
|
||||
|
||||
Reference in new issue
Block a user