main.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. import Vue from 'vue'
  2. import App from './App'
  3. import store from './store'
  4. let {
  5. config
  6. } = require('./common/util.js');
  7. Vue.config.productionTip = false
  8. App.mpType = 'app'
  9. Vue.prototype.$store = store
  10. import {
  11. mapState,
  12. mapMutations,
  13. mapActions
  14. } from 'vuex';
  15. Vue.mixin({
  16. data() {
  17. return {
  18. // api: api //引入api文件
  19. // wsBaseUrl
  20. menuinfo: {
  21. top: 0,
  22. height: 0
  23. },
  24. privacyShow: 0,
  25. privacyContractName: '',
  26. privacyed: 0,
  27. p: '',
  28. }
  29. },
  30. computed: {
  31. ...mapState(['hasLogin', 'userInfo', 'shop', 'geoinfo', 'redirctCurCate']),
  32. authorize() {
  33. return code => {
  34. if (`${this.userInfo.role_id}`.indexOf('1') > -1) {
  35. return true;
  36. }
  37. let arrCode = code.split(',');
  38. return arrCode.filter(item => {
  39. return `${this.userInfo.role_id || ''}`.indexOf(item) != -1
  40. }).length;
  41. }
  42. }
  43. },
  44. methods: {
  45. ...mapMutations(['login', 'setShop', 'setGeoInfo', 'setUserInfo', 'setRedirctCurCate']),
  46. ...mapActions(['doLogin', 'getUser']),
  47. setTabBarPath(path) {
  48. // if (typeof this.$mp.page.getTabBar === 'function' &&
  49. // this.$mp.page.getTabBar()) {
  50. // this.$mp.page.getTabBar().setData({
  51. // selectedPath: path
  52. // })
  53. // }
  54. },
  55. meShowLoading(opt) {
  56. uni.showLoading({
  57. title: '加载中',
  58. ...opt
  59. })
  60. },
  61. goToDetail(e) {
  62. let item = e.currentTarget.dataset.item;
  63. let type = item.type;
  64. // type=1是商品组,type=2是商品详情,type=3是文章详情,type_id就是商品组id、商品id、文章id
  65. switch(type) {
  66. case '-1':
  67. if(item.option == 2) {
  68. uni.switchTab({
  69. url: `/${item.link}`
  70. })
  71. } else {
  72. uni.navigateTo({
  73. url: `/${item.link}`
  74. })
  75. }
  76. break;
  77. case '1': {
  78. uni.navigateTo({
  79. url: `/pages/dinghuo/goods_group/goods_group?id=${item.type_id}`
  80. })
  81. }
  82. break;
  83. case '2': {
  84. uni.navigateTo({
  85. url: `/pages/dinghuo/goods_detail/goods_detail?id=${item.type_id}`
  86. })
  87. }
  88. break;
  89. case '3':
  90. uni.navigateTo({
  91. url: `/pages/dinghuo/goods_detail/redirector?id=${item.type_id}`
  92. })
  93. break;
  94. case '5':
  95. this.setRedirctCurCate(item.type_id)
  96. uni.switchTab({
  97. url: `/pages/app/shop/shop`
  98. })
  99. break;
  100. default:
  101. uni.navigateTo({
  102. url: `/pages/assets/webview/webview?link=${item.link}`
  103. })
  104. break;
  105. }
  106. },
  107. goBack() {
  108. if (getCurrentPages().length == 1) {
  109. uni.reLaunch({
  110. url: '/pages/app/index/index'
  111. })
  112. } else {
  113. uni.navigateBack({})
  114. }
  115. },
  116. formatPath(url) {
  117. return `${config.path}${url}&json=1&version=${config.version}&t=${this.userInfo.t}`
  118. },
  119. reqByuser: function(options) {
  120. if(!this.p) {
  121. let p = uni.getStorageSync('place')
  122. this.p = p;
  123. if(!this.p) {
  124. uni.showToast({
  125. icon: 'error',
  126. title: '缺少身份码'
  127. })
  128. return
  129. }
  130. }
  131. if (this.userInfo.t) {
  132. options.data = {
  133. ...options.data,
  134. ...config.data,
  135. p: this.p,
  136. t: this.userInfo.t
  137. };
  138. if(options.data.env) {
  139. options.data.env = 3;
  140. }
  141. options.url = `${config.path}${options.url}`;
  142. uni.request(options)
  143. } else {
  144. uni.navigateTo({
  145. url:'/pages/login/login'
  146. })
  147. uni.hideLoading()
  148. return Promise.reject('未登录')
  149. }
  150. },
  151. req: function(options) {
  152. if(!this.p) {
  153. let p = uni.getStorageSync('place')
  154. console.log(p)
  155. this.p = p;
  156. if(!this.p) {
  157. uni.showToast({
  158. icon: 'error',
  159. title: '缺少身份码'
  160. })
  161. return
  162. }
  163. }
  164. options.data = {
  165. ...options.data,
  166. ...config.data,
  167. p: this.p,
  168. };
  169. if(options.data.env) {
  170. options.data.env = 3;
  171. }
  172. if(options.url.indexOf('http') !== 0) {
  173. options.url = `${config.path}${options.url}`;
  174. }
  175. uni.request(options)
  176. },
  177. upload: function(options) {
  178. options.formData = {
  179. ...options.formData,
  180. ...config.data,
  181. json: 0
  182. };
  183. options.url = `${config.path}${options.url}`;
  184. uni.uploadFile(options)
  185. },
  186. refreshCartNum() {
  187. if (this.userInfo.t && this.$mp.page.route.indexOf('pages/app') > -1) {
  188. this.reqByuser({
  189. url: "src/sell/order/?l=cart.getNum",
  190. method: "GET",
  191. data: {
  192. },
  193. success: (d) => {
  194. if (d.data.status == 1) {
  195. if (d.data.data.total > 0) {
  196. uni.setTabBarBadge({
  197. index: 2,
  198. text: `${d.data.data.total}`
  199. })
  200. } else {
  201. uni.removeTabBarBadge({
  202. index: 2
  203. })
  204. }
  205. } else {
  206. uni.showToast({
  207. icon: "error",
  208. title: d.data.msg
  209. })
  210. }
  211. },
  212. });
  213. }
  214. },
  215. handleAgreePrivacyAuthorization() {
  216. this.privacyShow = 0
  217. this.resolvePrivacyAuthorization({ buttonId: 'agree-btn', event: 'agree' })
  218. },
  219. openPricacy() {
  220. wx.openPrivacyContract({
  221. success: () => {}, // 打开成功
  222. fail: () => {}, // 打开失败
  223. complete: () => {}
  224. })
  225. },
  226. loadUserInfo() {
  227. return new Promise((resolve, reject) => {
  228. this.reqByuser({
  229. url: '?l=user.info',
  230. data: {},
  231. success: res => {
  232. if(res.data.status == 1) {
  233. this.user = res.data.data.user;
  234. this.setUserInfo({...this.user, ...this.userInfo})
  235. resolve({user: {...this.user, ...this.userInfo}, order:res.data.data.order})
  236. }else {
  237. uni.showToast({
  238. icon: 'error',
  239. title: res.data.msg
  240. })
  241. reject(res.data.msg)
  242. }
  243. }
  244. })
  245. })
  246. },
  247. },
  248. onLoad(options) {
  249. if(options.p) {
  250. this.p = options.p;
  251. uni.setStorageSync('place', this.p)
  252. }
  253. // let menuinfo = uni.getMenuButtonBoundingClientRect();
  254. // this.menuinfo = menuinfo;
  255. // this.refreshCartNum()
  256. // if(wx.onNeedPrivacyAuthorization) {
  257. // console.log('onNeedPrivacyAuthorization')
  258. // wx.onNeedPrivacyAuthorization((resolve, eventInfo) => {
  259. // console.log('触发本次事件的接口是:' + eventInfo.referrer, eventInfo)
  260. // // 需要用户同意隐私授权时
  261. // // 弹出开发者自定义的隐私授权弹窗
  262. // this.privacyShow = 1
  263. // // this.privacyContractName = res.privacyContractName
  264. // this.resolvePrivacyAuthorization = resolve
  265. // })
  266. // }
  267. // wx.requirePrivacyAuthorize({
  268. // success: () => {
  269. // // 用户同意授权
  270. // // 继续小程序逻辑
  271. // },
  272. // fail: () => {}, // 用户拒绝授权
  273. // complete: () => {}
  274. // })
  275. }
  276. })
  277. const app = new Vue({
  278. store,
  279. ...App
  280. })
  281. app.$mount()