main.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. const vuexStore = require("@/store/$u.mixin.js");
  22. Vue.mixin(vuexStore);
  23. import webim from 'webim.js';
  24. Vue.config.productionTip = false
  25. Vue.prototype.$socket = webim;
  26. App.mpType = 'app'
  27. import * as filters from './filters'
  28. import * as config from './config'
  29. let urlAddress = 'liangxin.zthymaoyi.com'
  30. Vue.prototype.$url = 'https://'+urlAddress+'/upload/'
  31. Vue.prototype.$uploadUrl = 'https://'+urlAddress+'/file/upload'
  32. Vue.prototype.$ws = 'wss://'+urlAddress+'/chat'
  33. // let urlAddress = 'localhost'
  34. // Vue.prototype.$url = 'https://liangxin.zthymaoyi.com/upload/'
  35. // Vue.prototype.$uploadUrl = 'https://liangxin.zthymaoyi.com/file/upload'
  36. // Vue.prototype.$ws = 'ws://'+urlAddress+':9999/chat'
  37. Object.keys(filters).forEach(key => {
  38. Vue.filter(key, filters[key])
  39. })
  40. //#ifdef H5
  41. let jweixin = require('./components/jweixin-module')
  42. let jwx = require('./components/jweixin-module/jwx')
  43. Vue.mixin({
  44. onShow() {
  45. jwx.configWeiXin(jwx => {
  46. })
  47. }
  48. })
  49. //#endif
  50. const defConfig = config.def
  51. const msg = (title, duration = 3500, mask = false, icon = 'none') => {
  52. //统一提示方便全局修改
  53. if (Boolean(title) === false) {
  54. return;
  55. }
  56. uni.showToast({
  57. title,
  58. duration,
  59. mask,
  60. icon
  61. });
  62. }
  63. let userInfo = undefined
  64. const logout = () => {
  65. userInfo = undefined
  66. uni.removeStorage({
  67. key: 'userInfo'
  68. })
  69. }
  70. const setUserInfo = (i) => {
  71. userInfo = i
  72. }
  73. const isVip = () => {
  74. return userInfo && userInfo.level
  75. }
  76. let loginLock = false
  77. // 原微信小程序请求方式
  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. // 现app调用方式
  157. const doRequest = (method, url, data)=> {
  158. console.log(method,url,data)
  159. // let baseUrl = config.def().baseUrl
  160. let baseUrl = 'http://192.168.1.120:8090/'
  161. // 如果data为空
  162. if (!data) var data = []
  163. var arr = []
  164. arr.push(data)
  165. // 接口需要验证的可以将json转成数组添加值再调用
  166. // 不需要的可以直接data:data
  167. return new Promise((resolve, reject) => {
  168. uni.request({
  169. method: method,
  170. url: baseUrl +url,
  171. data: arr[0],
  172. // data:data
  173. header: {
  174. 'content-type': 'application/x-www-form-urlencoded'
  175. },
  176. success: function(result) {
  177. // resolve调用后,即可传递到调用方使用then或者async+await同步方式进行处理逻辑
  178. resolve(result)
  179. },
  180. fail: function(e) {
  181. console.log('error in...')
  182. // reject调用后,即可传递到调用方使用catch或者async+await同步方式进行处理逻辑
  183. reject(e)
  184. },
  185. })
  186. })
  187. }
  188. const uploadImg = (successCallback) => {
  189. let baseUrl = config.def().baseUrl
  190. uni.chooseImage({
  191. sizeType: ['compressed'],
  192. success: function(res) {
  193. for (let i = 0; i < res.tempFilePaths.length; i++) {
  194. uni.request({
  195. url: baseUrl + '/upload',
  196. method: 'get',
  197. success: function(signRes) {
  198. uni.showLoading({
  199. title: '图片上传中',
  200. })
  201. let fileName = ('imgs/' + random_string(15) + get_suffix(res.tempFilePaths[i]))
  202. uni.uploadFile({
  203. url: signRes.data.baseUrl,
  204. filePath: res.tempFilePaths[i],
  205. name: 'file',
  206. formData: {
  207. name: res.tempFilePaths[i],
  208. key: fileName,
  209. policy: signRes.data.policy,
  210. OSSAccessKeyId: signRes.data.accessid,
  211. success_action_status: '200',
  212. signature: signRes.data.signature
  213. },
  214. success: function(uploadRes) {
  215. uni.hideLoading()
  216. if (uploadRes.statusCode === 200) {
  217. if (successCallback) {
  218. successCallback(signRes.data.baseUrl + fileName)
  219. } else {
  220. uni.showToast({
  221. title: '上传成功',
  222. icon: 'none'
  223. })
  224. }
  225. } else {
  226. uni.hideLoading()
  227. uni.showToast({
  228. title: '网络错误 code=' + uploadRes.statusCode,
  229. icon: 'none'
  230. })
  231. }
  232. }
  233. })
  234. }
  235. })
  236. }
  237. }
  238. })
  239. }
  240. function get_suffix(filename) {
  241. var pos = filename.lastIndexOf('.')
  242. var suffix = ''
  243. if (pos != -1) {
  244. suffix = filename.substring(pos)
  245. }
  246. return suffix;
  247. }
  248. function random_string(len) {
  249. len = len || 32;
  250. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  251. var maxPos = chars.length;
  252. var pwd = '';
  253. for (var i = 0; i < len; i++) {
  254. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  255. }
  256. return pwd;
  257. }
  258. const prePage = () => {
  259. let pages = getCurrentPages();
  260. let prePage = pages[pages.length - 2];
  261. // #ifdef H5
  262. return prePage;
  263. // #endif
  264. return prePage.$vm;
  265. }
  266. const globalData = {}
  267. Vue.config.productionTip = false
  268. Vue.prototype.$fire = new Vue();
  269. Vue.prototype.$store = store;
  270. Vue.prototype.$api = {
  271. msg,
  272. prePage,
  273. request,
  274. uploadImg,
  275. doRequest,
  276. logout,
  277. isVip,
  278. setUserInfo,
  279. defConfig,
  280. globalData
  281. };
  282. //#ifdef H5
  283. Vue.prototype.$jweixin = jweixin;
  284. //#endif
  285. App.mpType = 'app'
  286. const app = new Vue({
  287. ...App
  288. })
  289. app.$mount()