import { defineStore } from 'pinia' import router from '@/router' interface SysState { /** * 状态栏高度 */ statusBarHeight: number /** * 胶囊按钮高度 */ MenuButtonHeight: number /** * 支付成功页面查看订单按钮跳转路径 * */ paySuccessPath: string /** * 支付成功页面返回首页按钮跳转路径 */ payBackIndexPath: string /** * 支付失败页面返回首页按钮跳转路径 */ payFailPath: string /** * 透明度 */ opcity: number /** * 是否上线审核 */ isOnlineAudit: boolean /** * 如果是组件模式加tabbar,从订单详情返回订单列表页面需要刷新,监听此字段刷新页面 */ refreshOrderList: boolean /** * 第三方名称 */ thirdPartyName: string /** * 三方logo */ thirdPartyLogo: string /** * 租户代码 */ tenantCode: string } export const useSysStore = defineStore('system', { state: (): SysState => ({ statusBarHeight: 0, MenuButtonHeight: 0, paySuccessPath: '', payBackIndexPath: '', payFailPath: '', opcity: 0, isOnlineAudit: true, refreshOrderList: false, thirdPartyName: '', thirdPartyLogo: '', tenantCode: '', }), actions: { getSystemData() { const { statusBarHeight } = uni.getSystemInfoSync() // #ifdef MP-WEIXIN const { height } = uni.getMenuButtonBoundingClientRect() this.MenuButtonHeight = height // #endif // #ifndef MP-WEIXIN this.MenuButtonHeight = 0 // #endif this.statusBarHeight = Number(statusBarHeight) }, /** * * @param payBackIndexPath 支付成功页面返回首页按钮跳转路径 * * @param paySuccessPath 支付成功页面查看订单按钮跳转路径 */ setPaySuccessPath(paySuccessPath: string, payBackIndexPath: string) { this.paySuccessPath = paySuccessPath this.payBackIndexPath = payBackIndexPath }, async getAudit() { const res = await Apis.sys.dictPage({ data: { typeCode: 'sys_applet' } }) this.isOnlineAudit = res.data?.list[0].value === '0' }, /** * 申请退款获取退款订单信息 * @param orderNumber * @returns */ async getRefunOrder(orderNumber: string) { uni.showLoading({ mask: true }) return new Promise((resolve, reject) => { Apis.xsb.findByOrderNumber({ data: { orderNumber, }, }).then((res) => { // resolve(res.data) router.push({ name: 'common-afterSales', params: { order: JSON.stringify(res.data) } }) uni.hideLoading() }).catch((err) => { reject(err) uni.hideLoading() }) }) }, /** * 获取第三方主题色 */ async getThirdPartyThemeColor() { if (this.tenantCode) return const accessId = this.getAccessIdFromPath() try { const res = await Apis.sys.appAccess({ pathParams: { accessId } }) this.thirdPartyName = res.data.accessName this.thirdPartyLogo = res.data.logoUrl this.tenantCode = res.data.tenantCode useManualThemeStore().setCurrentThemeColor({ name: '三方主题色', value: 'blue', primary: res.data.themeMainColor }) } catch { useGlobalToast().show('渠道有问题!,请联系管理员') } }, getAccessIdFromPath() { // 仅在 H5 下从地址路径中提取第一个路径段作为 accessId // #ifdef H5 const path = window.location.pathname || '' const cleanPath = path.split('?')[0].replace(/^\//, '') const [accessId] = cleanPath.split('/').filter(Boolean) return accessId || '' // #endif }, }, })