main.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. import Vue from 'vue'
  2. import store from './store'
  3. import App from './App'
  4. import share from './common/share.js'
  5. Vue.mixin(share)
  6. import cuCustom from './components/colorui/components/cu-custom.vue';
  7. Vue.component('cu-custom',cuCustom)
  8. import buy from './pages/buy/transaction.vue'
  9. Vue.component('buy',buy)
  10. import sale from './pages/sale/information.vue'
  11. Vue.component('sale',sale)
  12. import tarBar from './components/tarbar.vue'
  13. Vue.component('tar-bar', tarBar)
  14. import tran from './pages/tran/tran.vue'
  15. Vue.component('tran',tran)
  16. import my from './pages/user/user.vue'
  17. Vue.component('my',my)
  18. // main.js
  19. import uView from "./components/uview-ui";
  20. Vue.use(uView);
  21. Vue.config.productionTip = false
  22. const vuexStore = require("@/store/$u.mixin.js");
  23. Vue.mixin(vuexStore);
  24. import webim from 'webim.js';
  25. Vue.config.productionTip = false
  26. Vue.prototype.$socket = webim;
  27. App.mpType = 'app'
  28. import * as filters from './filters'
  29. import * as config from './config'
  30. let urlAddress = 'liangxin.zthymaoyi.com'
  31. Vue.prototype.$url = 'https://'+urlAddress+'/upload/'
  32. Vue.prototype.$uploadUrl = 'https://'+urlAddress+'/file/upload'
  33. Vue.prototype.$ws = 'wss://'+urlAddress+'/chat'
  34. // let urlAddress = 'localhost'
  35. // Vue.prototype.$url = 'https://liangxin.zthymaoyi.com/upload/'
  36. // Vue.prototype.$uploadUrl = 'https://liangxin.zthymaoyi.com/file/upload'
  37. // Vue.prototype.$ws = 'ws://'+urlAddress+':9999/chat'
  38. Object.keys(filters).forEach(key => {
  39. Vue.filter(key, filters[key])
  40. })
  41. //#ifdef H5
  42. let jweixin = require('./components/jweixin-module')
  43. let jwx = require('./components/jweixin-module/jwx')
  44. Vue.mixin({
  45. onShow() {
  46. jwx.configWeiXin(jwx => {
  47. })
  48. }
  49. })
  50. //#endif
  51. const defConfig = config.def
  52. const msg = (title, duration = 3500, mask = false, icon = 'none') => {
  53. //统一提示方便全局修改
  54. if (Boolean(title) === false) {
  55. return;
  56. }
  57. uni.showToast({
  58. title,
  59. duration,
  60. mask,
  61. icon
  62. });
  63. }
  64. let userInfo = undefined
  65. const logout = () => {
  66. userInfo = undefined
  67. uni.removeStorage({
  68. key: 'userInfo'
  69. })
  70. }
  71. const setUserInfo = (i) => {
  72. userInfo = i
  73. }
  74. const isVip = () => {
  75. return userInfo && userInfo.level
  76. }
  77. let loginLock = false
  78. const request = (_gp, _mt, data = {}, failCallback) => {
  79. //异步请求数据
  80. return new Promise(resolve => {
  81. if (!userInfo || !userInfo.accessToken) {
  82. userInfo = uni.getStorageSync('userInfo')
  83. }
  84. let accessToken = userInfo ? userInfo.accessToken : ''
  85. let baseUrl = config.def().baseUrl
  86. uni.request({
  87. url: baseUrl + '/m.api',
  88. data: {
  89. ...data,
  90. _gp,
  91. _mt
  92. },
  93. method: 'POST',
  94. header: {
  95. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  96. 'ACCESSTOKEN': accessToken
  97. },
  98. success: (res) => {
  99. if (res.statusCode === 200) {
  100. if (res.data.errno === 200) {
  101. resolve(res.data);
  102. } else if (res.data.errno === 10001) {
  103. if (failCallback) {
  104. failCallback(res.data)
  105. }
  106. uni.showModal({
  107. title: '登录提示',
  108. content: '您尚未登录,是否立即登录?',
  109. showCancel: true,
  110. confirmText: '登录',
  111. success: (e) => {
  112. if (e.confirm) {
  113. uni.navigateTo({
  114. url: '/pages/public/login'
  115. })
  116. }
  117. },
  118. fail: () => {},
  119. complete: () => {}
  120. })
  121. if (!loginLock) {
  122. loginLock = true
  123. // uni.showModal({
  124. // title: '登录提示',
  125. // content: '您尚未登录,是否立即登录?',
  126. // showCancel: false,
  127. // confirmText: '登录',
  128. // success: (e) => {
  129. // if (e.confirm) {
  130. // uni.navigateTo({
  131. // url: '/pages/public/login'
  132. // })
  133. // }
  134. // },
  135. // fail: () => {},
  136. // complete: () => {
  137. // loginLock = false
  138. // }
  139. // })
  140. }
  141. } else {
  142. if (failCallback) {
  143. failCallback(res.data)
  144. } else {
  145. uni.showToast({
  146. title: res.data.errmsg,
  147. icon: 'none'
  148. })
  149. }
  150. }
  151. }
  152. }
  153. })
  154. })
  155. }
  156. const uploadImg = (successCallback) => {
  157. let baseUrl = config.def().baseUrl
  158. uni.chooseImage({
  159. sizeType: ['compressed'],
  160. success: function(res) {
  161. for (let i = 0; i < res.tempFilePaths.length; i++) {
  162. uni.request({
  163. url: baseUrl + '/upload',
  164. method: 'get',
  165. success: function(signRes) {
  166. uni.showLoading({
  167. title: '图片上传中',
  168. })
  169. let fileName = ('imgs/' + random_string(15) + get_suffix(res.tempFilePaths[i]))
  170. uni.uploadFile({
  171. url: signRes.data.baseUrl,
  172. filePath: res.tempFilePaths[i],
  173. name: 'file',
  174. formData: {
  175. name: res.tempFilePaths[i],
  176. key: fileName,
  177. policy: signRes.data.policy,
  178. OSSAccessKeyId: signRes.data.accessid,
  179. success_action_status: '200',
  180. signature: signRes.data.signature
  181. },
  182. success: function(uploadRes) {
  183. uni.hideLoading()
  184. if (uploadRes.statusCode === 200) {
  185. if (successCallback) {
  186. successCallback(signRes.data.baseUrl + fileName)
  187. } else {
  188. uni.showToast({
  189. title: '上传成功',
  190. icon: 'none'
  191. })
  192. }
  193. } else {
  194. uni.hideLoading()
  195. uni.showToast({
  196. title: '网络错误 code=' + uploadRes.statusCode,
  197. icon: 'none'
  198. })
  199. }
  200. }
  201. })
  202. }
  203. })
  204. }
  205. }
  206. })
  207. }
  208. function get_suffix(filename) {
  209. var pos = filename.lastIndexOf('.')
  210. var suffix = ''
  211. if (pos != -1) {
  212. suffix = filename.substring(pos)
  213. }
  214. return suffix;
  215. }
  216. function random_string(len) {
  217. len = len || 32;
  218. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  219. var maxPos = chars.length;
  220. var pwd = '';
  221. for (var i = 0; i < len; i++) {
  222. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  223. }
  224. return pwd;
  225. }
  226. const prePage = () => {
  227. let pages = getCurrentPages();
  228. let prePage = pages[pages.length - 2];
  229. // #ifdef H5
  230. return prePage;
  231. // #endif
  232. return prePage.$vm;
  233. }
  234. const globalData = {}
  235. Vue.config.productionTip = false
  236. Vue.prototype.$fire = new Vue();
  237. Vue.prototype.$store = store;
  238. Vue.prototype.$api = {
  239. msg,
  240. prePage,
  241. request,
  242. uploadImg,
  243. logout,
  244. isVip,
  245. setUserInfo,
  246. defConfig,
  247. globalData
  248. };
  249. //#ifdef H5
  250. Vue.prototype.$jweixin = jweixin;
  251. //#endif
  252. App.mpType = 'app'
  253. const app = new Vue({
  254. ...App
  255. })
  256. app.$mount()