sys.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. import { defineStore } from 'pinia'
  2. import router from '@/router'
  3. interface SysState {
  4. /**
  5. * 状态栏高度
  6. */
  7. statusBarHeight: number
  8. /**
  9. * 胶囊按钮高度
  10. */
  11. MenuButtonHeight: number
  12. /**
  13. * 支付成功页面查看订单按钮跳转路径
  14. *
  15. */
  16. paySuccessPath: string
  17. /**
  18. * 支付成功页面返回首页按钮跳转路径
  19. */
  20. payBackIndexPath: string
  21. /**
  22. * 支付失败页面返回首页按钮跳转路径
  23. */
  24. payFailPath: string
  25. /**
  26. * 透明度
  27. */
  28. opcity: number
  29. /**
  30. * 是否上线审核
  31. */
  32. isOnlineAudit: boolean
  33. /**
  34. * 如果是组件模式加tabbar,从订单详情返回订单列表页面需要刷新,监听此字段刷新页面
  35. */
  36. refreshOrderList: boolean
  37. /**
  38. * 第三方名称
  39. */
  40. thirdPartyName: string
  41. /**
  42. * 三方logo
  43. */
  44. thirdPartyLogo: string
  45. /**
  46. * 租户代码
  47. */
  48. tenantCode: string
  49. }
  50. export const useSysStore = defineStore('system', {
  51. state: (): SysState => ({
  52. statusBarHeight: 0,
  53. MenuButtonHeight: 0,
  54. paySuccessPath: '',
  55. payBackIndexPath: '',
  56. payFailPath: '',
  57. opcity: 0,
  58. isOnlineAudit: true,
  59. refreshOrderList: false,
  60. thirdPartyName: '',
  61. thirdPartyLogo: '',
  62. tenantCode: '',
  63. }),
  64. actions: {
  65. getSystemData() {
  66. const { statusBarHeight } = uni.getSystemInfoSync()
  67. // #ifdef MP-WEIXIN
  68. const { height } = uni.getMenuButtonBoundingClientRect()
  69. this.MenuButtonHeight = height
  70. // #endif
  71. // #ifndef MP-WEIXIN
  72. this.MenuButtonHeight = 0
  73. // #endif
  74. this.statusBarHeight = Number(statusBarHeight)
  75. },
  76. /**
  77. *
  78. * @param payBackIndexPath 支付成功页面返回首页按钮跳转路径
  79. *
  80. * @param paySuccessPath 支付成功页面查看订单按钮跳转路径
  81. */
  82. setPaySuccessPath(paySuccessPath: string, payBackIndexPath: string) {
  83. this.paySuccessPath = paySuccessPath
  84. this.payBackIndexPath = payBackIndexPath
  85. },
  86. async getAudit() {
  87. const res = await Apis.sys.dictPage({ data: { typeCode: 'sys_applet' } })
  88. this.isOnlineAudit = res.data?.list[0].value === '0'
  89. },
  90. /**
  91. * 申请退款获取退款订单信息
  92. * @param orderNumber
  93. * @returns
  94. */
  95. async getRefunOrder(orderNumber: string) {
  96. uni.showLoading({ mask: true })
  97. return new Promise((resolve, reject) => {
  98. Apis.xsb.findByOrderNumber({
  99. data: {
  100. orderNumber,
  101. },
  102. }).then((res) => {
  103. // resolve(res.data)
  104. router.push({ name: 'common-afterSales', params: { order: JSON.stringify(res.data) } })
  105. uni.hideLoading()
  106. }).catch((err) => {
  107. reject(err)
  108. uni.hideLoading()
  109. })
  110. })
  111. },
  112. /**
  113. * 获取第三方主题色
  114. */
  115. async getThirdPartyThemeColor() {
  116. if (this.tenantCode)
  117. return
  118. const accessId = this.getAccessIdFromPath()
  119. try {
  120. const res = await Apis.sys.appAccess({ pathParams: { accessId } })
  121. this.thirdPartyName = res.data.accessName
  122. this.thirdPartyLogo = res.data.logoUrl
  123. this.tenantCode = res.data.tenantCode
  124. useManualThemeStore().setCurrentThemeColor({ name: '三方主题色', value: 'blue', primary: res.data.themeMainColor })
  125. }
  126. catch {
  127. useGlobalToast().show('渠道有问题!,请联系管理员')
  128. }
  129. },
  130. getAccessIdFromPath() {
  131. // 仅在 H5 下从地址路径中提取第一个路径段作为 accessId
  132. // #ifdef H5
  133. const path = window.location.pathname || ''
  134. const cleanPath = path.split('?')[0].replace(/^\//, '')
  135. const [accessId] = cleanPath.split('/').filter(Boolean)
  136. return accessId || ''
  137. // #endif
  138. },
  139. },
  140. })