diff --git a/src/App.vue b/src/App.vue
index 75f3258..ab4bab0 100644
--- a/src/App.vue
+++ b/src/App.vue
@@ -67,181 +67,179 @@ const tabbar = [
]
export default {
- onLaunch() {
+ async onLaunch() {
+ if (isDevEnv()) return
+
console.log("环境判断")
// 诗画浦江获取用户信息进行环境判断
- ;(window as any).CP2.getAppInfo().then(async (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
+ const res = await (window as any).CP2.getAppInfo()
+ 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 {
+ // 是诗画环境
+ const userRole = uni.getStorageSync("userRole")
+ if (userRole && userRole == "user") uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
+ if (userRole && userRole == "merchant") uni.switchTab({ url: "/pages/tabbar/individualOrder" })
+
+ const res = await user.isMerchant()
+ if (res.code == 0) {
+ if (res.data) {
+ return uni.redirectTo({ url: "/pages/user/userRole" })
+ } else {
+ uni.setStorageSync("userRole", "user")
+ uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
}
} else {
- // 是诗画环境
- const userRole = uni.getStorageSync("userRole")
- if (userRole && userRole == "user") uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
- if (userRole && userRole == "merchant") uni.switchTab({ url: "/pages/tabbar/individualOrder" })
-
- const res = await user.isMerchant()
- if (res.code == 0) {
- if (res.data) {
- return uni.redirectTo({ url: "/pages/user/userRole" })
- } else {
- uni.setStorageSync("userRole", "user")
- uni.switchTab({ url: "/pages/tabbar/coopMerchant" })
- }
- } else {
- uni.showToast({ title: "角色身份判断失败", icon: "none" })
- }
+ uni.showToast({ title: "角色身份判断失败", icon: "none" })
}
- })
+ }
},
onShow() {},
onHide() {},
methods: {
- _initTabbar() {
- // const launchPath = uni.getLaunchOptionsSync().path
- // console.log("启动路径", launchPath)
+ async _initTabbar() {
+ if (isDevEnv()) {
+ tabbar.forEach(({ pagePath, text, iconPath, selectedIconPath, authPath, auth }, index) => {
+ uni.setTabBarItem({
+ index,
+ pagePath,
+ text,
+ iconPath,
+ selectedIconPath,
+ visible: true,
+ })
+ })
+ return
+ }
const launchParam = new URL(window.location.href).searchParams.get("launchParam")
console.log("tabbar launch 启动路径参数", launchParam)
// 诗画浦江获取用户信息进行环境判断
- ;(window as any).CP2.getAppInfo().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,
- })
+ const res = await (window as any).CP2.getAppInfo()
+ if (res.code == 0) {
+ // 不是诗画环境
+ 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 {
- 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,
- })
- }
+ 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,
})
- 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,
- })
- }
+ } else {
+ uni.setTabBarItem({
+ index,
+ pagePath,
+ text,
+ iconPath,
+ selectedIconPath,
+ visible: false,
})
- 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
- }
+ }
+ })
+ 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 b193088..d49c846 100644
--- a/src/pages.json
+++ b/src/pages.json
@@ -313,6 +313,13 @@
"navigationBarTitleText": "支付完成",
"disableScroll": true
}
+ },
+ {
+ "path": "transferMoney",
+ "style": {
+ "navigationBarTitleText": "转账",
+ "disableScroll": true
+ }
}
]
}
diff --git a/src/pages/pay/scanPay.vue b/src/pages/pay/scanPay.vue
index 2ff1389..dffa552 100644
--- a/src/pages/pay/scanPay.vue
+++ b/src/pages/pay/scanPay.vue
@@ -9,63 +9,7 @@
支付
-
-
-
- {{ key }}
-
-
-
-
- .
-
-
- 0
-
-
-
-
-
-
+
@@ -78,13 +22,9 @@ import payApi from "@@/api/pay"
import { storePrice } from "@/sheep/utils/formatMoney"
import { router } from "@/sheep"
import { merchantApi } from "@/sheep/api"
+import numberKeyboard from "@/sheep/components/numberKeyboard.vue"
const amount = ref("")
-const keyboardLayout = ref([
- ["1", "2", "3"],
- ["4", "5", "6"],
- ["7", "8", "9"],
-])
const scanData = ref<{ id?: string; name?: string }>({})
const disabled = ref(false)
@@ -113,27 +53,6 @@ const displayAmount = computed(() => {
)
})
-// 按下键盘
-const handleKeyPress = (key) => {
- if (key === "." && amount.value.includes(".")) return
- if (key === "." && !amount.value) {
- amount.value = "0."
- return
- }
-
- if (amount.value.includes(".")) {
- const decimalPlaces = amount.value.split(".")[1]
- if (decimalPlaces && decimalPlaces.length >= 2) return
- }
-
- amount.value += key
-}
-
-// 点击删除
-const handleDelete = () => {
- amount.value = amount.value.slice(0, -1)
-}
-
// 点击支付
const handlePay = () => {
if (!scanData.value.id || !scanData.value.name) return uni.showToast({ title: "扫码信息不存在", icon: "none" })
diff --git a/src/pages/pay/transferMoney.vue b/src/pages/pay/transferMoney.vue
new file mode 100644
index 0000000..4c76a70
--- /dev/null
+++ b/src/pages/pay/transferMoney.vue
@@ -0,0 +1,197 @@
+
+
+
+
+
+ {{ transferMoney.sourceWalletType.walletTypeName }}
+
+
+ 余额:
+ {{ hooks.useMoney(transferMoney.sourceWalletType.balance) + "元" }}
+
+
+
+
+
+
+ 转入到
+
+
+ {{ state.targetWalletTypeName }}
+
+
+
+
+
+ 转账金额
+
+ ¥
+ 转账金额
+ {{ formattedAmount }}
+
+
+
+
+
+ 注:转账金额不能超过钱包余额
+
+
+
+
+ 确定转账
+
+
+
+
+
+
+
+
+
+
+
+ {{ v.walletTypeName }}
+ {{ v.cardNumber }}
+
+
+ 余额:{{ hooks.useMoney(v.balance) + "元" }}
+
+
+
+
+
+ 确 定
+
+
+
+
+
+
+
diff --git a/src/pages/wallet/detail.vue b/src/pages/wallet/detail.vue
index ce5c934..7d8cb23 100644
--- a/src/pages/wallet/detail.vue
+++ b/src/pages/wallet/detail.vue
@@ -71,6 +71,7 @@ const doTab = (e: any) => {
{{ v.title }}
{{ v.title }}
{{ v.title }}
+ {{ v.title }}
{{ hooks.useMoney(v.price) }}元
diff --git a/src/pages/wallet/list.vue b/src/pages/wallet/list.vue
index cec451c..5b7926f 100644
--- a/src/pages/wallet/list.vue
+++ b/src/pages/wallet/list.vue
@@ -8,6 +8,7 @@ import { hooks, router } from "@@/index"
import { merchantApi, walletApi } from "@@/api"
import { filePath } from "@@/utils/file"
+import { useTransferMoney } from "@/sheep/stores/transferMoney"
const state = reactive({
showBindDialog: false,
@@ -119,6 +120,16 @@ const doFreeze = async () => {
uni.hideLoading()
}
}
+
+// 转账
+const doTransferMoney = (v: any) => {
+ if (v.walletTypeId) {
+ useTransferMoney().setSourceWalletType(v)
+ router.jump("/pages/pay/transferMoney")
+ return
+ }
+ uni.showToast({ title: "钱包类型id不存在", icon: "none" })
+}
@@ -173,6 +184,7 @@ const doFreeze = async () => {
+ 转账
申请冻结
diff --git a/src/sheep/api/pay.ts b/src/sheep/api/pay.ts
index feb10bf..13def0f 100644
--- a/src/sheep/api/pay.ts
+++ b/src/sheep/api/pay.ts
@@ -61,4 +61,15 @@ export default {
},
})
},
+ // 转账
+ transferMoney: (data): Promise => {
+ return request({
+ url: "/wallet/wallet-rule-transaction/app/transfer-accounts",
+ method: "POST",
+ data,
+ custom: {
+ showLoading: false,
+ },
+ })
+ },
}
diff --git a/src/sheep/api/wallet.ts b/src/sheep/api/wallet.ts
index d1c6340..5b92043 100644
--- a/src/sheep/api/wallet.ts
+++ b/src/sheep/api/wallet.ts
@@ -1,7 +1,7 @@
import request from "@/sheep/utils/request"
export default {
- all: () =>
+ all: (): Promise =>
request({
url: "/wallet/wallet-manage/app/get-all",
method: "GET",
diff --git a/src/sheep/components/numberKeyboard.vue b/src/sheep/components/numberKeyboard.vue
new file mode 100644
index 0000000..5a15966
--- /dev/null
+++ b/src/sheep/components/numberKeyboard.vue
@@ -0,0 +1,75 @@
+
+
+
+
+ {{ key }}
+
+
+
+
+ .
+
+
+ 0
+
+
+
+
+
+
+
+
+
diff --git a/src/sheep/stores/transferMoney.ts b/src/sheep/stores/transferMoney.ts
new file mode 100644
index 0000000..a33f46a
--- /dev/null
+++ b/src/sheep/stores/transferMoney.ts
@@ -0,0 +1,14 @@
+import { defineStore } from "pinia"
+
+export const useTransferMoney = defineStore("transferMoney", {
+ state: (): any => {
+ return {
+ sourceWalletType: {},
+ }
+ },
+ actions: {
+ setSourceWalletType(data: any) {
+ this.sourceWalletType = data
+ },
+ },
+})
diff --git a/src/sheep/utils/request.ts b/src/sheep/utils/request.ts
index ed26edf..4b98e7e 100644
--- a/src/sheep/utils/request.ts
+++ b/src/sheep/utils/request.ts
@@ -4,22 +4,170 @@ import isDevEnv from "./isDevEnv"
import { router, constant } from "@@/index"
import { userApi } from "../api"
-// 定义常量
+// 常量定义
const TOKEN_KEY = constant.storageConstant.TOKEN
const USER_INFO_KEY = constant.storageConstant.USERINFO
-// Loading 管理
-const LoadingInstance: { target: any; count: number } = {
+// Loading 状态管理
+const LoadingInstance = {
target: null,
count: 0,
}
-// 关闭 loading
+// 关闭加载提示
function closeLoading() {
if (LoadingInstance.count > 0) LoadingInstance.count--
if (LoadingInstance.count === 0) uni.hideLoading()
}
+// 显示加载提示
+function showLoading(message: string) {
+ LoadingInstance.count++
+ if (LoadingInstance.count === 1) {
+ uni.showLoading({
+ title: message,
+ mask: true,
+ fail: () => uni.hideLoading(),
+ })
+ }
+}
+
+// 读取token并处理Authorization请求头
+const getAuthHeader = (tokenStorage: any) => {
+ if (isDevEnv()) {
+ return tokenStorage?.access_token ? `Bearer ${tokenStorage.access_token}` : null
+ }
+ return tokenStorage?.accessToken?.tokenValue ? `Bearer ${tokenStorage.accessToken.tokenValue}` : null
+}
+
+// 浙政钉登录 登录成功返回true,否则返回false
+async function handleZzdLogin(): Promise {
+ try {
+ uni.showLoading({ title: "加载中...", mask: true })
+ const params = new URL(window.location.href).searchParams
+ const token = params.get("uabaseToken")
+
+ if (!token) return false
+
+ const res = await userApi.auth(token)
+ if (res?.code === 0) {
+ uni.setStorageSync(TOKEN_KEY, res.data)
+ const { data: userData } = await userApi.userInfo()
+ uni.setStorageSync(USER_INFO_KEY, userData)
+ return true
+ } else {
+ uni.removeStorageSync(TOKEN_KEY)
+ uni.removeStorageSync(USER_INFO_KEY)
+ uni.showToast({ title: res.msg || "登录失败", icon: "none" })
+ return false
+ }
+ } catch (error) {
+ uni.showToast({ title: "登录错误", icon: "none" })
+ return false
+ } finally {
+ uni.hideLoading()
+ }
+}
+
+// 诗画登录 登录成功返回true,否则返回false
+async function handleShLogin(): Promise {
+ try {
+ uni.showLoading({ title: "登录中...", mask: true })
+ const userInfo = await (window as any).CP2.getUserInfo()
+
+ if (userInfo.code == 0) {
+ uni.showToast({ title: "获取诗画用户信息失败", icon: "none" })
+ return false
+ }
+
+ const { accountId, sessionId } = userInfo.data
+ const response = await userApi.authsh({ accountId, sessionId })
+
+ if (response.code == 0) {
+ uni.setStorageSync(TOKEN_KEY, { accessToken: response.data.accessToken })
+ const { data: userData } = await userApi.userInfo()
+ uni.setStorageSync(USER_INFO_KEY, userData)
+ uni.showToast({ title: "登录成功", icon: "none" })
+ return true
+ } else {
+ uni.showToast({ title: "获取用户信息失败", icon: "none" })
+ return false
+ }
+ } catch (error) {
+ uni.showToast({ title: "登录错误", icon: "none" })
+ return false
+ } finally {
+ uni.hideLoading()
+ }
+}
+
+// 根据应用环境自动登录 返回登录结果
+async function autoLogin(): Promise {
+ const appInfo = await (window as any).CP2.getAppInfo()
+
+ // 浙政钉环境
+ if (appInfo.code == 0) {
+ return await handleZzdLogin()
+ }
+ // 诗画环境
+ else {
+ return await handleShLogin()
+ }
+}
+
+// token过期刷新检查
+async function checkAndRefreshToken(tokenStorage: any) {
+ const { accessToken } = tokenStorage
+ if (!accessToken) return
+
+ const expiresDate = new Date(accessToken.expiresAt).getTime()
+
+ // console.log("过期时间", expiresDate)
+ // console.log("现在时间", new Date().getTime())
+ // console.log("现在时间大于过期时间吗", new Date().getTime() >= expiresDate)
+
+ // token已过期,尝试刷新
+ if (new Date().getTime() >= expiresDate) {
+ await autoLogin()
+ }
+}
+
+// 处理错误响应
+function handleErrorResponse(response: any) {
+ if (!response.config?.custom?.showError) return
+
+ switch (response.data.code) {
+ case 401:
+ // 处理未授权情况
+ setTimeout(() => {
+ uni.removeStorageSync(TOKEN_KEY)
+ uni.removeStorageSync(USER_INFO_KEY)
+ }, 500)
+ break
+ case 424:
+ // 处理token过期
+ autoLogin()
+ break
+ default:
+ uni.showToast({
+ title: response.data.msg || "服务器开小差啦,请稍后再试~",
+ icon: "none",
+ mask: true,
+ })
+ }
+}
+
+// 处理成功提示
+function handleSuccessMessage(response: any) {
+ const { data, config } = response
+ if (data.code === 0 && data.message && config?.custom?.showSuccess) {
+ uni.showToast({
+ title: config.custom.successMsg || data.message,
+ icon: "none",
+ })
+ }
+}
+
// 创建请求实例
const http = new Request({
baseURL: import.meta.env.VITE_API_URL,
@@ -31,88 +179,16 @@ const http = new Request({
},
withCredentials: true,
custom: {
- showSuccess: false,
- // 成功提醒 默认使用后端返回值
- successMsg: "",
- // 显示失败消息 默认显示
- showError: true,
- // 失败提醒 默认使用后端返回信息
- errorMsg: "",
- // 显示请求时loading模态框 默认显示
- showLoading: true,
- // loading提醒文字
- loadingMsg: "加载中",
- // 需要授权才能请求 默认放开
- auth: false,
+ showSuccess: false, // 成功提醒 默认使用后端返回值
+ successMsg: "", // 成功消息
+ showError: true, // 显示失败消息 默认显示
+ errorMsg: "", // 失败提醒 默认使用后端返回信息
+ showLoading: true, // 显示请求时loading模态框 默认显示
+ loadingMsg: "加载中", // loading提醒文字
+ auth: false, // 需要授权才能请求 默认放开
},
})
-// 读取token 处理Authorization请求头
-const getAuthHeader = (tokenStorage: any) => {
- if (isDevEnv()) {
- return tokenStorage?.access_token ? `Bearer ${tokenStorage.access_token}` : null
- }
- return tokenStorage?.accessToken?.tokenValue ? `Bearer ${tokenStorage.accessToken.tokenValue}` : null
-}
-
-// token过期刷新检查
-const checkAndRefreshToken = async (tokenStorage: any) => {
- const { accessToken } = tokenStorage
- if (!accessToken) return
-
- const expiresDate = new Date(accessToken.expiresAt).getTime()
- // console.log("现在的时间大于过期时间吗:", new Date().getTime() >= expiresDate)
-
- if (new Date().getTime() >= expiresDate) {
- const appInfo = await (window as any).CP2.getAppInfo()
- if (appInfo.code == 0) {
- try {
- uni.showLoading({ title: "加载中...", mask: true })
- const params = new URL(window.location.href).searchParams
- const token = params.get("uabaseToken")
- if (token) {
- const res = await userApi.auth(token)
- if (res?.code === 0) {
- uni.setStorageSync(TOKEN_KEY, res.data)
- } else {
- uni.removeStorageSync(TOKEN_KEY)
- uni.removeStorageSync(USER_INFO_KEY)
- uni.showToast({ title: res.msg, icon: "none" })
- }
- }
- } catch (error) {
- uni.showToast({ title: "错误", icon: "none" })
- } finally {
- uni.hideLoading()
- }
- } else {
- // 诗画
- try {
- uni.showLoading({ title: "登录中...", mask: true })
- const userInfo = await (window as any).CP2.getUserInfo()
- if (userInfo.code == 0) {
- return uni.showToast({ title: "获取诗画用户信息失败", icon: "none" })
- } else {
- const { accountId, sessionId } = userInfo.data
- const response = await userApi.authsh({ accountId, sessionId })
- if (response.code == 0) {
- uni.setStorageSync(TOKEN_KEY, { accessToken: response.data.accessToken })
- uni.showToast({ title: "登录成功", icon: "none" })
- const { data: userData } = await userApi.userInfo()
- uni.setStorageSync(USER_INFO_KEY, userData)
- } else {
- uni.showToast({ title: "获取用户信息失败", icon: "none" })
- }
- }
- } catch (error) {
- uni.showToast({ title: "错误", icon: "none" })
- } finally {
- uni.hideLoading()
- }
- }
- }
-}
-
// 请求拦截器
http.interceptors.request.use(async (config) => {
const tokenStorage = uni.getStorageSync(TOKEN_KEY)
@@ -126,25 +202,19 @@ http.interceptors.request.use(async (config) => {
// 处理 loading
if (config.custom?.showLoading) {
- LoadingInstance.count++
- if (LoadingInstance.count === 1) {
- uni.showLoading({
- title: config.custom.loadingMsg,
- mask: true,
- fail: () => uni.hideLoading(),
- })
- }
+ showLoading(config.custom.loadingMsg)
}
- // 设置认证头
- if (
- !config.url?.startsWith("/thirdparty/thirdPartyOAth2") &&
- config.url !== "/sys/auth/refresh-token" &&
- config.url !== "/auth/oauth2/token"
- ) {
+ // 不需要设置认证头的接口
+ const skipAuthUrls = ["/thirdparty/thirdPartyOAth2", "/sys/auth/refresh-token", "/auth/oauth2/token"]
+
+ // 判断是否需要设置认证头
+ const needAuth = !skipAuthUrls.some((url) => config.url?.startsWith(url))
+
+ if (needAuth) {
if (!isEmpty(tokenStorage)) {
// token过期刷新检查
- checkAndRefreshToken(tokenStorage)
+ await checkAndRefreshToken(tokenStorage)
const authHeader = getAuthHeader(tokenStorage)
if (authHeader) {
@@ -152,57 +222,13 @@ http.interceptors.request.use(async (config) => {
}
} else {
// token不存在,则发起登录
- const appInfo = await (window as any).CP2.getAppInfo()
- if (appInfo.code == 0) {
- // 浙政钉
- const params = new URL(window.location.href).searchParams
- const token = params.get("uabaseToken")
- if (token) {
- try {
- uni.showLoading({ title: "加载中...", mask: true })
- const res = await userApi.auth(token)
- if (res.code == 0) {
- uni.setStorageSync(TOKEN_KEY, res.data)
- const { data: userData } = await userApi.userInfo()
- uni.setStorageSync(USER_INFO_KEY, userData)
+ await autoLogin()
- const authHeader = getAuthHeader(tokenStorage)
- if (authHeader) {
- config_header.Authorization = authHeader
- }
- } else {
- uni.showToast({ title: "获取浙政钉用户信息失败", icon: "none" })
- }
- } catch (error) {
- uni.showToast({ title: "错误", icon: "none" })
- } finally {
- uni.hideLoading()
- }
- }
- } else {
- // 诗画
- try {
- uni.showLoading({ title: "登录中...", mask: true })
- const userInfo = await (window as any).CP2.getUserInfo()
- if (userInfo.code == 0) {
- return uni.showToast({ title: "获取诗画用户信息失败", icon: "none" })
- } else {
- const { accountId, sessionId } = userInfo.data
- const response = await userApi.authsh({ accountId, sessionId })
- if (response.code == 0) {
- uni.setStorageSync(TOKEN_KEY, { accessToken: response.data.accessToken })
- uni.showToast({ title: "登录成功", icon: "none" })
- const { data: userData } = await userApi.userInfo()
- uni.setStorageSync(USER_INFO_KEY, userData)
- } else {
- uni.showToast({ title: "获取用户信息失败", icon: "none" })
- }
- }
- } catch (error) {
- uni.showToast({ title: "错误", icon: "none" })
- } finally {
- uni.hideLoading()
- }
+ // 登录后重新获取token
+ const newTokenStorage = uni.getStorageSync(TOKEN_KEY)
+ const authHeader = getAuthHeader(newTokenStorage)
+ if (authHeader) {
+ config_header.Authorization = authHeader
}
}
}
@@ -210,91 +236,6 @@ http.interceptors.request.use(async (config) => {
return config
}, Promise.reject)
-// 处理错误响应
-const handleErrorResponse = async (response: any) => {
- if (!response.config?.custom?.showError) return
-
- switch (response.data.code) {
- case 401:
- // 处理未授权情况
- setTimeout(() => {
- uni.removeStorageSync(TOKEN_KEY)
- uni.removeStorageSync(USER_INFO_KEY)
- // console.log("未授权")
- }, 500)
- break
- case 424:
- const appInfo = await (window as any).CP2.getAppInfo()
- if (appInfo.code == 0) {
- try {
- const params = new URL(window.location.href).searchParams
- const token = params.get("uabaseToken")
- if (token) {
- userApi.auth(token).then((res) => {
- if (res?.code === 0) {
- uni.setStorageSync(TOKEN_KEY, res.data)
- } else {
- uni.removeStorageSync(TOKEN_KEY)
- uni.removeStorageSync(USER_INFO_KEY)
- // uni.showToast({ title: "登录已过期", icon: "none" })
- return Promise.resolve({
- code: 1,
- data: "登录已过期",
- msg: "登录已过期",
- })
- }
- })
- }
- } catch (error) {
- uni.hideLoading()
- uni.showToast({ title: "错误", icon: "none" })
- }
- } else {
- // 诗画
- try {
- uni.showLoading({ title: "登录中...", mask: true })
- const userInfo = await (window as any).CP2.getUserInfo()
- if (userInfo.code == 0) {
- return uni.showToast({ title: "获取诗画用户信息失败", icon: "none" })
- } else {
- const { accountId, sessionId } = userInfo.data
- const response = await userApi.authsh({ accountId, sessionId })
- if (response.code == 0) {
- uni.setStorageSync(TOKEN_KEY, { accessToken: response.data.accessToken })
- uni.showToast({ title: "登录成功", icon: "none" })
- const { data: userData } = await userApi.userInfo()
- uni.setStorageSync(USER_INFO_KEY, userData)
- } else {
- uni.showToast({ title: "获取用户信息失败", icon: "none" })
- }
- }
- } catch (error) {
- uni.showToast({ title: "错误", icon: "none" })
- } finally {
- uni.hideLoading()
- }
- }
- break
- default:
- uni.showToast({
- title: response.data.msg || "服务器开小差啦,请稍后再试~",
- icon: "none",
- mask: true,
- })
- }
-}
-
-// 处理成功提示
-const handleSuccessMessage = (response: any) => {
- const { data, config } = response
- if (data.code === 0 && data.message && config?.custom?.showSuccess) {
- uni.showToast({
- title: config.custom.successMsg || data.message,
- icon: "none",
- })
- }
-}
-
// 响应拦截器
http.interceptors.response.use(
async (response) => {
@@ -324,6 +265,11 @@ http.interceptors.response.use(
return Promise.resolve(response.data)
},
async (error) => {
+ // 处理 loading
+ if (error.config?.custom?.showLoading) {
+ closeLoading()
+ }
+
// 处理 424 错误(token过期)
if (error.statusCode === 424) {
if (isDevEnv()) {
@@ -334,58 +280,7 @@ http.interceptors.response.use(
router.jump("/pages/test/login")
return false
} else {
- const appInfo = await (window as any).CP2.getAppInfo()
- if (appInfo.code == 0) {
- try {
- uni.showLoading({ title: "加载中...", mask: true })
- const params = new URL(window.location.href).searchParams
- const token = params.get("uabaseToken")
- if (token) {
- userApi.auth(token).then((res) => {
- if (res?.code === 0) {
- uni.setStorageSync(TOKEN_KEY, res.data)
- } else {
- uni.removeStorageSync(TOKEN_KEY)
- uni.removeStorageSync(USER_INFO_KEY)
- // uni.showToast({ title: "登录已过期", icon: "none" })
- return Promise.resolve({
- code: 1,
- data: "登录已过期",
- msg: "登录已过期",
- })
- }
- })
- }
- } catch (error) {
- uni.showToast({ title: "错误", icon: "none" })
- } finally {
- uni.hideLoading()
- }
- } else {
- // 诗画
- try {
- uni.showLoading({ title: "登录中...", mask: true })
- const userInfo = await (window as any).CP2.getUserInfo()
- if (userInfo.code == 0) {
- return uni.showToast({ title: "获取诗画用户信息失败", icon: "none" })
- } else {
- const { accountId, sessionId } = userInfo.data
- const response = await userApi.authsh({ accountId, sessionId })
- if (response.code == 0) {
- uni.setStorageSync(TOKEN_KEY, { accessToken: response.data.accessToken })
- uni.showToast({ title: "登录成功", icon: "none" })
- const { data: userData } = await userApi.userInfo()
- uni.setStorageSync(USER_INFO_KEY, userData)
- } else {
- uni.showToast({ title: "获取用户信息失败", icon: "none" })
- }
- }
- } catch (error) {
- uni.showToast({ title: "错误", icon: "none" })
- } finally {
- uni.hideLoading()
- }
- }
+ await autoLogin()
}
}
@@ -397,10 +292,11 @@ http.interceptors.response.use(
mask: true,
})
}
- return false
+ return Promise.resolve(error.data)
},
)
+// 请求函数
const request = (config: any) => {
return http.middleware(config)
}
diff --git a/src/static/page/arrow-right.svg b/src/static/page/arrow-right.svg
new file mode 100644
index 0000000..cea3368
--- /dev/null
+++ b/src/static/page/arrow-right.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/static/page/keyboardDelete.svg b/src/static/page/keyboardDelete.svg
new file mode 100644
index 0000000..894a7ee
--- /dev/null
+++ b/src/static/page/keyboardDelete.svg
@@ -0,0 +1,26 @@
+
\ No newline at end of file
diff --git a/src/static/page/money-cny-circle-fill.svg b/src/static/page/money-cny-circle-fill.svg
new file mode 100644
index 0000000..6a27b17
--- /dev/null
+++ b/src/static/page/money-cny-circle-fill.svg
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/src/uni_modules/tm-ui/components/tm-cell/tm-cell.vue b/src/uni_modules/tm-ui/components/tm-cell/tm-cell.vue
index f235244..1f9a450 100644
--- a/src/uni_modules/tm-ui/components/tm-cell/tm-cell.vue
+++ b/src/uni_modules/tm-ui/components/tm-cell/tm-cell.vue
@@ -1,74 +1,89 @@
-
-
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
- {{ _allAttr.title
- }}
-
-
-
- {{
- _allAttr.desc }}
-
-
-
-
-
- {{ _allAttr.label }}
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
\ No newline at end of file
+