main.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. import App from './App'
  2. import md5Libs from "./uview-ui/libs/function/md5.js";
  3. import url from "./common/url.js"
  4. // #ifndef VUE3
  5. import Vue from 'vue'
  6. import Socket from "./common/websocket.js"
  7. var amapFile = require('./common/amap-wx.js');
  8. Vue.prototype.$Socket = Socket
  9. Vue.prototype.$tologin = function(msg){
  10. if (msg == '请登录。' || msg == '账号在其他地方登录,请重新登录。'){
  11. uni.removeStorageSync("token")
  12. setTimeout(() => {
  13. uni.navigateTo({
  14. url:"/pages/mine/login-wx"
  15. })
  16. },800)
  17. }
  18. },
  19. Vue.prototype.myAmapFun = new amapFile.AMapWX({
  20. key: 'daba801a5b8eb18e2aee6d0838ea4c61'
  21. });
  22. Vue.prototype.$md5 = md5Libs.md5
  23. Vue.prototype.$url = url
  24. Vue.prototype.$openimg = function(arr, count = 0) {
  25. uni.previewImage({
  26. urls: arr,
  27. current: count
  28. })
  29. }
  30. Vue.prototype.$tophone = function(tel, str) {
  31. if (str) {
  32. this.$u.toast(str)
  33. } else {
  34. uni.makePhoneCall({
  35. phoneNumber: tel
  36. })
  37. }
  38. }
  39. Vue.prototype.$openad = function(obj) {
  40. // 广告类型(1、类别;2、服务;3、链接;4、商家;5、文章;6、关键字;7水电服务,8呼叫代驾,9跑腿服务,10申请服务,11商城,12商城商品,13查看大图)
  41. if (obj.advertise_type == 5) {
  42. uni.navigateTo({
  43. url: "/pages/index/wenzhang?id=" + obj.source_code
  44. })
  45. return
  46. }
  47. if (obj.advertise_type == 7) {
  48. uni.navigateTo({
  49. url: "/pages/index/weixiu"
  50. })
  51. return
  52. }
  53. if (obj.advertise_type == 8) {
  54. uni.navigateTo({
  55. url: "/pages/index/daijia"
  56. })
  57. return
  58. }
  59. if (obj.advertise_type == 9) {
  60. uni.navigateTo({
  61. url: "/pages/index/paotui"
  62. })
  63. return
  64. }
  65. if (obj.advertise_type == 11) {
  66. uni.switchTab({
  67. url: "/pages/shop/shop"
  68. })
  69. return
  70. }
  71. if (obj.advertise_type == 12) {
  72. uni.navigateTo({
  73. url: "/pages/shop/goods-info?id=" + obj.business_product.id
  74. })
  75. return
  76. }
  77. uni.showModal({
  78. content: `新的type=${obj.advertise_type}`
  79. })
  80. console.log(obj);
  81. }
  82. Vue.prototype.$getdata = function() {
  83. var timestamp = parseInt(new Date().getTime() / 1000)
  84. var secret_key = 'cXab5HR4pfBjdDryr2JjwbreieKVjA'
  85. var params = {}
  86. var str = '';
  87. for (var Key in params) {
  88. str += Key + '=' + params[Key] + '&';
  89. }
  90. var sign = md5Libs.md5(`${str}timestamp=${timestamp}&secret_key=${secret_key}`)
  91. // console.log(`${str}timestamp=${timestamp}&secret_key=${secret_key}`);
  92. var phonetype = uni.getSystemInfoSync().model
  93. var header = {}
  94. header.sign = sign
  95. header.timestamp = timestamp
  96. header.phonetype = phonetype
  97. header.category = 3
  98. header.secret_key = secret_key
  99. header.token = uni.getStorageSync('token');
  100. // config.data.header.debug = "5CDAC27A0F89C916553DE870F3C55181"//默认登录
  101. return {
  102. request: JSON.stringify({
  103. header: header
  104. })
  105. }
  106. }
  107. Vue.prototype.$opencode = function() {
  108. // if (!uni.getStorageSync("token")) {
  109. // this.$u.toast("请登录")
  110. // setTimeout(() => {
  111. // uni.navigateTo({
  112. // url: "/pages/mine/login-wx"
  113. // })
  114. // }, 800)
  115. // return
  116. // }
  117. uni.scanCode({
  118. success: (res) => {
  119. console.log(res);
  120. var query = res.result.split("?")[1]
  121. if (query) {
  122. var vars = query.split("&");
  123. var xiaoma_type
  124. for (var i = 0; i < vars.length; i++) {
  125. var pair = vars[i].split("=");
  126. if (pair[0] == 'xiaoma_type') {
  127. xiaoma_type = pair[1]
  128. }
  129. }
  130. for (var i = 0; i < vars.length; i++) {
  131. var pair = vars[i].split("=");
  132. if (pair[0] == 'xiaoma_code') {
  133. // 去核销
  134. if (xiaoma_type == 7) {
  135. uni.navigateTo({
  136. url: "/pages/shop/shop-orderinfo?url=" + pair[1]
  137. })
  138. }
  139. // 去注册
  140. if (xiaoma_type == 2) {
  141. if (uni.getStorageSync("token")) {
  142. this.$u.toast("当前账户已被邀请")
  143. } else {
  144. uni.showModal({
  145. content: "邀请码:" + pair[1],
  146. confirmText: "去注册",
  147. success: (on) => {
  148. if (on.confirm) {
  149. uni.navigateTo({
  150. url: "/pages/mine/login-wx?yqm=" + pair[1]
  151. })
  152. }
  153. }
  154. })
  155. }
  156. }
  157. return;
  158. }
  159. }
  160. this.$u.toast('缺少参数')
  161. } else {
  162. this.$u.toast('缺少参数')
  163. }
  164. },
  165. fail(e) {
  166. // uni.showModal({
  167. // content:JSON.stringify(e)
  168. // })
  169. }
  170. })
  171. }
  172. uni.$tabbar = [{
  173. "iconPath": "/static/images/index1.png",
  174. "selectedIconPath": "/static/images/index.png",
  175. "pagePath": "/pages/index/home",
  176. "text": "主页"
  177. },
  178. {
  179. "iconPath": "/static/images/order1.png",
  180. "selectedIconPath": "/static/images/order.png",
  181. "pagePath": "/pages/order/order",
  182. "text": "订单",
  183. "count": 0
  184. },
  185. // {
  186. // "iconPath": "/static/images/shop1.png",
  187. // "selectedIconPath": "/static/images/shop.png",
  188. // "pagePath": "/pages/shop/shop",
  189. // "text": "商城"
  190. // },
  191. {
  192. "iconPath": "/static/images/mine1.png",
  193. "selectedIconPath": "/static/images/mine.png",
  194. "pagePath": "/pages/mine/mine",
  195. "text": "我的"
  196. }
  197. ]
  198. // main.js
  199. import uView from 'uview-ui';
  200. Vue.use(uView);
  201. Vue.config.productionTip = false
  202. App.mpType = 'app'
  203. const app = new Vue({
  204. ...App
  205. })
  206. // http拦截器,此为需要加入的内容,如果不是写在common目录,请自行修改引入路径
  207. import httpInterceptor from '@/common/http.interceptor.js'
  208. // 这里需要写在最后,是为了等Vue创建对象完成,引入"app"对象(也即页面的"this"实例)
  209. Vue.use(httpInterceptor, app)
  210. app.$mount()
  211. // #endif
  212. // #ifdef VUE3
  213. import {
  214. createSSRApp
  215. } from 'vue'
  216. export function createApp() {
  217. const app = createSSRApp(App)
  218. return {
  219. app
  220. }
  221. }
  222. // #endif