main.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // #ifndef VUE3
  2. import Vue from 'vue'
  3. import App from './App'
  4. // 导入网络请求的包
  5. import {
  6. $http
  7. } from '@escook/request-miniprogram'
  8. import {
  9. formatDate,
  10. sortASCII
  11. } from '@/utils.js'
  12. import crypto from 'crypto'
  13. Vue.config.productionTip = false
  14. App.mpType = 'app'
  15. uni.$http = $http
  16. // 请求的根路径
  17. $http.baseUrl = 'https://api.ijolijoli.com/'
  18. // 请求拦截器
  19. $http.beforeRequest = function(options) {
  20. // 当前发送请求时间
  21. let req_time = formatDate(new Date(), 'YYYYMMDDhhmmss')
  22. let app_id = '10020'
  23. let key = 'c2c1d3893504d063d7b30c0fc553c1b2'
  24. options.data.app_id=app_id
  25. options.data.req_time = req_time
  26. // 参数排序
  27. let sortObj = sortASCII(options.data, true)
  28. sortObj.key = key
  29. // 拼接参数
  30. let mdd = []
  31. let fnAdd = function(key, value) {
  32. return key + '=' + value
  33. }
  34. for (var k in sortObj) {
  35. mdd.push(fnAdd(k, sortObj[k]))
  36. }
  37. // 转成md5加密
  38. mdd=mdd.join('&')
  39. const md5 = crypto.createHash('md5')
  40. md5.update(mdd)
  41. const sign = md5.digest('hex')
  42. options.data.sign = sign
  43. }
  44. // 响应拦截器
  45. $http.afterRequest = function() {}
  46. const app = new Vue({
  47. ...App
  48. })
  49. app.$mount()
  50. // #endif
  51. // #ifdef VUE3
  52. import {
  53. createSSRApp
  54. } from 'vue'
  55. import App from './App.vue'
  56. import {
  57. log
  58. } from 'console'
  59. export function createApp() {
  60. const app = createSSRApp(App)
  61. return {
  62. app
  63. }
  64. }
  65. // #endif