Преглед изворни кода

基础架构+散户加气3.1

chenlei пре 1 година
родитељ
комит
58cb04ab28

+ 4 - 0
src/types/api.d.ts

@@ -140,6 +140,10 @@ interface IRequestExt {
   fileCount?: number
   /** 追加url */
   appendUrl?: string
+  /** 最小请求时长 ms */
+  minRTime?: number
+  /** 临时记录请求时间戳 ms */
+  _tempRtimespan?: number
 }
 /** 分页返回数据 */
 type IPage<T> = {

+ 3 - 0
src/utils/api/web/request/before.ts

@@ -22,6 +22,9 @@ export default {
       url: options.urlObj.getUrl(),
       header: this.getHeader(options),
     }
+    if (options.ext.minRTime) {
+      options.ext._tempRtimespan = Date.now()
+    }
     if (options.ext.appendUrl) {
       rv.url += options.ext.appendUrl
     }

+ 6 - 3
src/utils/api/web/request/com.ts

@@ -1,8 +1,11 @@
 const com = {
   complete: {
     async main(args: { options: IRequestOption }) {
-      if (store.common.data.debug) {
-        await func.awaiter()
+      if (args.options.ext._tempRtimespan) {
+        const awaitTime = args.options.ext.minRTime - (Date.now() - args.options.ext._tempRtimespan)
+        if (awaitTime > 0) {
+          await func.awaiter(awaitTime)
+        }
       }
       if (args.options.ext.showLoading) {
         if (--com.loading.count === 0) {
@@ -24,7 +27,7 @@ const com = {
       })
     },
     hide() {
-      uni.hideLoading()
+      uni.hideLoading({ noConflict: true })
     },
   },
 }

+ 9 - 9
src/utils/config/interFaces/index.ts

@@ -1,33 +1,33 @@
 import websocket from './websocket'
-import gasdata from './gasdata'
-import account from './account'
 import allinpay from './allinpay'
 import tms from './tms'
+import account from './account'
 import message from './message'
-import pay from './pay'
+import gasdata from './gasdata'
 import settle from './settle'
 import user from './user'
 import strategy from './strategy'
+import pay from './pay'
 
 export default {
   /** websocket打印中心 */
   websocket,
-  /** 加气站数据采集 */
-  gasdata,
-  /** 账户中心 */
-  account,
   /** 通联支付 */
   allinpay,
   /** 运力中心 */
   tms,
+  /** 账户中心 */
+  account,
   /** 消息中心 */
   message,
-  /** 支付中心 */
-  pay,
+  /** 加气站数据采集 */
+  gasdata,
   /** 结算中心 */
   settle,
   /** 用户中心 */
   user,
   /** 运营策略中心 */
   strategy,
+  /** 支付中心 */
+  pay,
 }

+ 1 - 1
src/utils/config/interFaces/pay.ts

@@ -75,7 +75,7 @@ export default {
   find_unpayfordriver: {
     realUrl: '/pay/gas_order/find_unpayfordriver' as const,
 
-    resType: {} as any,
+    resType: {} as GasOrder对象,
   },
   /** 根据司机id查询当前司机是否首次下单支付完成 */
   first_finished_order_check: {

+ 2 - 1
src/utils/container/index.ts

@@ -28,7 +28,8 @@ export default {
               rv.finally(() => {
                 executings[k] = false
                 if (ext[k]?.showLoading) {
-                  uni.hideLoading()
+                  // 在调用hideLoading与hideToast时配置参数noConflict: true取消混用特性,解决hideLoading隐藏showToast提示的问题。
+                  uni.hideLoading({ noConflict: true })
                 }
               })
             } else {

+ 30 - 0
src/utils/func/native.ts

@@ -1,4 +1,34 @@
 export default {
+  async scan() {
+    if (store.common.data.debug) {
+      return {
+        cashierId: '710613333157822464',
+        gasstationId: '710613333157822464',
+
+        orgId: '720613316032479232',
+      }
+    }
+    const reqStr = await uni
+      .scanCode({
+        scanType: ['qrcode'],
+      })
+      .catch((err) => {
+        // 二维码解析失败
+        if (err.errMsg !== 'scanCode:fail cancel') {
+          func.native.showToast('二维码无效')
+        }
+        return Promise.reject(err)
+      })
+    let ret = {}
+    try {
+      ret = JSON.parse(reqStr.result)
+    } catch {
+      // 反序列化失败
+      func.native.showToast('二维码无效')
+      return Promise.reject(new Error('反序列化失败'))
+    }
+    return ret
+  },
   /** 获取当前的地理位置、速度, 获取失败不阻塞,返回默认经纬度 */
   getLocation() {
     return uni.getLocation().catch(() => {

+ 6 - 2
src/utils/store/user.ts

@@ -1,6 +1,7 @@
 import { defineStore } from 'pinia'
 import { ref } from 'vue'
 import { Base64 } from 'js-base64'
+import defHead from '@img/icons/turnk_number_head.png'
 interface TUser extends Token认证用户实体 {
   /** 令牌 */
   token?: string
@@ -10,6 +11,7 @@ interface TUser extends Token认证用户实体 {
   roleId?: string
   /** 请求时携带的标识符 */
   Identifier?: string
+  mobileDes?: string
 }
 const service = 'miniprogram'
 const initState = {
@@ -26,9 +28,11 @@ const useUserStore = defineStore(
     const initUserInfo = (val: Token认证返回实体) => {
       const data = { ...val.user }
       delete data.authorities
-
-      data.mobile = func.convert.mobileDes(data.mobile)
+      if (!data.head_url) {
+        data.head_url = defHead
+      }
       userInfo.value = data
+      userInfo.value.mobileDes = func.convert.mobileDes(data.mobile)
       userInfo.value.token = val.access_token
       userInfo.value.orgId = val.user.authorities[0].orgId
       userInfo.value.roleId = val.user.authorities[0].roles[0].roleId