main.js 5.9 KB

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