From c18f79e01a2705d34d5ac2923a26913dba07ea14 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期六, 03 八月 2024 16:04:18 +0800
Subject: [PATCH] 2024-08-03

---
 src/api/index.js |  127 +++++++++++++++++++++---------------------
 1 files changed, 64 insertions(+), 63 deletions(-)

diff --git a/src/api/index.js b/src/api/index.js
index 09170ce..7d3ae5f 100644
--- a/src/api/index.js
+++ b/src/api/index.js
@@ -15,7 +15,8 @@
 window.GLOB.$error = false
 
 let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : ''
-let db = `mkdb${service}`
+let lang = sessionStorage.getItem('lang') !== 'zh-CN' ? sessionStorage.getItem('lang') : ''
+let db = `mkdb${service + lang}`
 
 if (window.indexedDB) {
   CacheUtils.openIndexDB(db)
@@ -97,37 +98,21 @@
   }
 
   /**
-   * @description 寰俊涓氬姟璇锋眰
+   * @description 寰俊涓氬姟璇锋眰 鍘熸帴鍙� 'wxpay/getaccesstoken'
    */
-  wxAccessToken (domain = '') {
-    let _url = window.GLOB.baseurl + 'wxpay/getaccesstoken'
+  wxAccessToken (appId, domain = '') {
+    let _url = domain || window.GLOB.baseurl
 
-    if (domain) {
-      _url = domain + 'wxpay/getaccesstoken'
-    }
-
-    return new Promise(resolve => {
-      if (window.GLOB.accessToken.domain === domain && window.GLOB.accessToken.accessTime && (parseInt(new Date().getTime() / 1000) - window.GLOB.accessToken.accessTime < 30)) {
-        resolve(window.GLOB.accessToken)
-      } else {
-        window.GLOB.accessToken = {domain}
-        axios({
-          url: _url,
-          method: 'get'
-        }).then(res => {
-          if (res.oa_access_token || res.mini_access_token) {
-            window.GLOB.accessToken.accessTime = parseInt(new Date().getTime() / 1000)
-            window.GLOB.accessToken.oa_access_token = res.oa_access_token
-            window.GLOB.accessToken.mini_access_token = res.mini_access_token
-          }
-          resolve(res)
-        })
-      }
+    return axios({
+      url: _url + 'wechat/getaccesstoken',
+      method: 'post',
+      data: JSON.stringify({app_id: appId})
     })
   }
 
   /**
    * @description 寰俊涓氬姟璇锋眰
+   * 39涓� qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn
    */
   wxNginxRequest (url, method, param) {
     let _url = url
@@ -137,17 +122,12 @@
       if (process.env.NODE_ENV === 'production') {
         _url = document.location.origin + '/' + url
       }
-      if (/^http:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
-        _url = window.GLOB.location + ':8080/' + url
-        if (process.env.NODE_ENV === 'production') {
-          _url = document.location.origin + ':8080/' + url
-        }
-      } else if (/^https:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
-        _url = window.GLOB.location + ':8443/' + url
-        if (process.env.NODE_ENV === 'production') {
-          _url = document.location.origin + ':8443/' + url
-        }
-      }
+    }
+    if (/qingqiumarket.cn|cloud.mk9h.cn/.test(_url)) {
+      _url = _url.replace('http://qingqiumarket.cn/', 'http://qingqiumarket.cn:8080/')
+      _url = _url.replace('http://cloud.mk9h.cn/', 'http://cloud.mk9h.cn:8080/')
+      _url = _url.replace('https://qingqiumarket.cn/', 'https://qingqiumarket.cn:8443/')
+      _url = _url.replace('https://cloud.mk9h.cn/', 'https://cloud.mk9h.cn:8443/')
     }
     
     if (param) {
@@ -167,7 +147,27 @@
   /**
    * @description 鐩存帴璇锋眰
    */
-  directRequest (params) {
+  directRequest (params, script, position) {
+    if (script) {
+      try {
+        // eslint-disable-next-line
+        let func = new Function('axios', 'Api', 'param', 'position', 'systemType', 'notification', script)
+        let promise = func(axios, this, params, position, window.GLOB.systemType, notification)
+
+        if (promise instanceof Promise) {
+          return promise
+        }
+      } catch (e) {
+        console.warn(e)
+      }
+
+      return Promise.resolve({
+        status: false,
+        message: '鑷畾涔夎剼鏈墽琛岄敊璇�',
+        ErrCode: 'E'
+      })
+    }
+    
     return axios(params)
   }
 
@@ -401,7 +401,7 @@
 
         this.getSystemConfig(param).then(res => {
           if (!res.status) {
-            reject()
+            reject(res.message)
             return
           }
 
@@ -441,7 +441,7 @@
 
           CacheUtils.updateIndexDBversion({version: res.app_version || '1.00', createDate: curTime})
 
-          resolve()
+          resolve(list)
         })
       }, () => {
         reject()
@@ -865,8 +865,8 @@
     if (script) {
       try {
         // eslint-disable-next-line
-        let func = new Function('axios', 'Api', 'param', 'position', 'systemType', script)
-        let promise = func(axios, this, param, position, window.GLOB.systemType)
+        let func = new Function('axios', 'Api', 'param', 'position', 'systemType', 'notification', script)
+        let promise = func(axios, this, param, position, window.GLOB.systemType, notification)
 
         if (promise instanceof Promise) {
           return promise
@@ -940,7 +940,7 @@
       })
     } else {
       let url = '/webapi/dostars'
-      if (param.rduri && !window.GLOB.transfer && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') {
+      if (param.rduri && (!window.GLOB.transfer || /https:\/\/sso.mk9h.cn/.test(param.rduri)) && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') {
         url = param.rduri
         delete param.rduri
       }
@@ -1028,16 +1028,11 @@
     if (process.env.NODE_ENV === 'production') {
       _url = document.location.origin + '/file/oss/upload'
     }
-    if (/^http:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
-      _url = window.GLOB.location + ':8080/file/oss/upload'
-      if (process.env.NODE_ENV === 'production') {
-        _url = document.location.origin + ':8080/file/oss/upload'
-      }
-    } else if (/^https:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
-      _url = window.GLOB.location + ':8443/file/oss/upload'
-      if (process.env.NODE_ENV === 'production') {
-        _url = document.location.origin + ':8443/file/oss/upload'
-      }
+    if (/qingqiumarket.cn|cloud.mk9h.cn/.test(_url)) {
+      _url = _url.replace('http://qingqiumarket.cn/', 'http://qingqiumarket.cn:8080/')
+      _url = _url.replace('http://cloud.mk9h.cn/', 'http://cloud.mk9h.cn:8080/')
+      _url = _url.replace('https://qingqiumarket.cn/', 'https://qingqiumarket.cn:8443/')
+      _url = _url.replace('https://cloud.mk9h.cn/', 'https://cloud.mk9h.cn:8443/')
     }
     
     return axios({
@@ -1049,15 +1044,24 @@
   }
 
   /**
-   * @description 鑾峰彇寰俊鏀粯浜岀淮鐮�
+   * @description 鑾峰彇寰俊鏀粯浜岀淮鐮� 鍘熸帴鍙xpay/wxNativePay
    */
   getWxNativePay (param) {
-    let _url = window.GLOB.baseurl + 'wxpay/wxNativePay'
-
     return axios({
-      url: _url,
+      url: window.GLOB.baseurl + 'wechat/native',
       method: 'post',
-      data: qs.stringify(param)
+      data: JSON.stringify(param)
+    })
+  }
+
+  /**
+   * @description 寰俊鏀粯閫�娆� 鍘熸帴鍙xpay/wxRefund
+   */
+  setRefund (param) {
+    return axios({
+      url: window.GLOB.baseurl + 'wechat/wxRefund',
+      method: 'post',
+      data: JSON.stringify(param)
     })
   }
 
@@ -1072,7 +1076,7 @@
   /**
    * @description sql妫�楠�
    */
-  sDebug (sql, rduri = null) {
+  sDebug (sql) {
     let param = {
       func: 's_debug_sql',
       exec_type: window.GLOB.execType || 'y',
@@ -1091,13 +1095,14 @@
     sql = sql.replace(/@SessionUid@/ig, `'${localStorage.getItem('SessionUid')}'`)
     sql = sql.replace(/@UserID@/ig, `'${sessionStorage.getItem('UserID')}'`)
     sql = sql.replace(/@Appkey@/ig, `'${window.GLOB.appkey}'`)
+    sql = sql.replace(/@lang@/ig, `'${sessionStorage.getItem('lang')}'`)
     // sql = sql.replace(/@datam@/ig, `''`)
 
     if (window.GLOB.externalDatabase !== null) {
       sql = sql.replace(/@db@/ig, window.GLOB.externalDatabase)
     }
 
-    console.info(`/* sql 楠岃瘉 */\n${sql.replace(/\n\s{6,20}/ig, '\n')}`)
+    window.mkInfo(`/* sql 楠岃瘉 */\n${sql.replace(/\n\s{6,20}/ig, '\n')}`)
 
     sql = sql.replace(/\n/ig, ' ')
 
@@ -1107,10 +1112,6 @@
     param = this.encryptParam(param)
 
     let url = '/webapi/dostars'
-
-    if (rduri) {
-      url = rduri
-    }
 
     let timer = setTimeout(() => {
       let _param = {

--
Gitblit v1.8.0