main.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import App from './App'
  2. import Vue from 'vue'
  3. import './uni.promisify.adaptor'
  4. import uView from "uview-ui";
  5. Vue.use(uView);
  6. Vue.config.productionTip = false
  7. import './css/style.css'
  8. import mySwiper from './components/my-swiper/my-swiper.vue';
  9. Vue.component('my-swiper', mySwiper);
  10. import useEmpty from './components/use-empty/use-empty.vue';
  11. Vue.component('use-empty', useEmpty);
  12. import useLoadmore from './components/use-loadmore/use-loadmore.vue';
  13. Vue.component('use-loadmore', useLoadmore);
  14. import topSearch from './components/top-search/top-search.vue';
  15. Vue.component('top-search', topSearch);
  16. import myGap from './components/my-gap/my-gap.vue';
  17. Vue.component('my-gap', myGap);
  18. import myGoods from './components/my-goods/my-goods.vue';
  19. Vue.component('my-goods', myGoods);
  20. import sendType from './components/send-type/send-type.vue';
  21. Vue.component('send-type', sendType);
  22. import useListTitle from './components/use-list-title/use-list-title.vue';
  23. Vue.component('use-list-title', useListTitle);
  24. // 配置项
  25. const config = process.env.ENV_PATH ? require(process.env.ENV_PATH) : require('./env/dev.js')
  26. Vue.prototype.serverPath = config.serverPath // 请求路径
  27. Vue.prototype.serverFilePath = config.serverFilePath // 文件路径
  28. Vue.prototype.appName = config.name // 应用名称
  29. Vue.prototype.appVersion = config.appVersion // 小程序版本
  30. Vue.prototype.webSocketURL = config.webSocketURL // socket 链接
  31. Vue.prototype.logo = config.logo //
  32. Vue.prototype.appId = config.appId // 微信小程序 appid
  33. Vue.prototype.$isIphoneX = false
  34. Vue.prototype.$request = function(method, url, data, isJSON, hideLoading, showErrMsg) {
  35. return new Promise((resolve) => {
  36. if (!hideLoading) {
  37. uni.showLoading({
  38. title: '请稍后...'
  39. })
  40. }
  41. // 过滤 null,undefind,'' 的参数
  42. for (let key in data) {
  43. if (data[key] === null || data[key] === undefined || data[key] === '') {
  44. delete data[key]
  45. }
  46. }
  47. const token = uni.getStorageSync('token');
  48. const tenantId = uni.getStorageSync('tenantId');
  49. if (tenantId) {
  50. data.tenantId = tenantId;
  51. }
  52. url = url.indexOf('http') === 0 ? url : `${Vue.prototype.serverPath}${url}`;
  53. uni.request({
  54. url,
  55. method,
  56. data,
  57. header: {
  58. "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
  59. // 'Content-Type': isJSON ? '' : 'application/x-www-form-urlencoded',
  60. // 'Authorization': `Bearer ${token}`,
  61. 'Authorization': 'Bearer ' + token,
  62. clientId: '8871d05eacc4406083d3bb0a085b6999',
  63. // 'tenantId': Vue.prototype.tenantId
  64. // 'tenantId': `${tenantId}`
  65. },
  66. success: (res) => {
  67. uni.hideLoading();
  68. if (res.data.code === 200) {
  69. resolve(res.data);
  70. } else {
  71. if (showErrMsg) {
  72. resolve({
  73. result: false,
  74. msg: res.data.msg
  75. })
  76. } else {
  77. resolve(false);
  78. if (this.$refs && this.$refs.uNotify) {
  79. this.$refs.uNotify.show({
  80. type: 'error',
  81. top: 0,
  82. message: res.data.msg,
  83. icon: 'error-circle'
  84. })
  85. }
  86. }
  87. }
  88. },
  89. fail: (err) => {
  90. uni.hideLoading()
  91. resolve(false)
  92. }
  93. })
  94. })
  95. }
  96. Vue.prototype.autoLogin = async () => { // 小程序自动登录
  97. return new Promise(resolve => {
  98. uni.login({
  99. success: async (res) => {
  100. const result = await Vue.prototype.$request('post', '/miniLogin', {
  101. code: res.code,
  102. appid: '000000'
  103. //appid: Vue.prototype.appId
  104. })
  105. if (result) {
  106. uni.setStorageSync("token", result.data.access_token);
  107. //await Vue.prototype.getUser()
  108. resolve(true)
  109. } else {
  110. uni.showModal({
  111. title: '温馨提示',
  112. content: '您尚未注册,是否前往注册?',
  113. showCancel: true,
  114. confirmText: '去注册',
  115. success: (response) => {
  116. if (response.confirm) {
  117. // 用户点击确定
  118. uni.navigateTo({
  119. url: '/pages/bindPhone/bindPhone'
  120. })
  121. resolve(true)
  122. } else if (response.cancel) {
  123. // 用户点击取消
  124. resolve(false)
  125. }
  126. },
  127. fail: () => {
  128. resolve(false)
  129. }
  130. })
  131. }
  132. },
  133. fail: (e) => {
  134. resolve(false)
  135. }
  136. })
  137. })
  138. }
  139. // 拼接文件完整地址
  140. Vue.prototype.getFilePath = (path) => {
  141. return `${Vue.prototype.serverFilePath}${path}`
  142. }
  143. App.mpType = 'app'
  144. const app = new Vue({
  145. ...App
  146. })
  147. app.$mount()
  148. // #ifdef VUE3
  149. import {
  150. createSSRApp
  151. } from 'vue'
  152. export function createApp() {
  153. const app = createSSRApp(App)
  154. return {
  155. app
  156. }
  157. }
  158. // #endif