main.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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 = 'http://192.168.1.120:8090/'
  86. let baseUrl = config.def().baseUrl
  87. uni.request({
  88. url: baseUrl + '/m.api',
  89. data: {
  90. ...data,
  91. _gp,
  92. _mt
  93. },
  94. method: 'POST',
  95. header: {
  96. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  97. 'ACCESSTOKEN': accessToken
  98. },
  99. success: (res) => {
  100. if (res.statusCode === 200) {
  101. if (res.data.errno === 200) {
  102. resolve(res.data);
  103. } else if (res.data.errno === 10001) {
  104. if (failCallback) {
  105. failCallback(res.data)
  106. }
  107. uni.showModal({
  108. title: '登录提示',
  109. content: '您尚未登录,是否立即登录?',
  110. showCancel: true,
  111. confirmText: '登录',
  112. success: (e) => {
  113. if (e.confirm) {
  114. uni.navigateTo({
  115. url: '/pages/public/login'
  116. })
  117. }
  118. },
  119. fail: () => {},
  120. complete: () => {}
  121. })
  122. if (!loginLock) {
  123. loginLock = true
  124. // uni.showModal({
  125. // title: '登录提示',
  126. // content: '您尚未登录,是否立即登录?',
  127. // showCancel: false,
  128. // confirmText: '登录',
  129. // success: (e) => {
  130. // if (e.confirm) {
  131. // uni.navigateTo({
  132. // url: '/pages/public/login'
  133. // })
  134. // }
  135. // },
  136. // fail: () => {},
  137. // complete: () => {
  138. // loginLock = false
  139. // }
  140. // })
  141. }
  142. } else {
  143. if (failCallback) {
  144. failCallback(res.data)
  145. } else {
  146. uni.showToast({
  147. title: res.data.errmsg,
  148. icon: 'none'
  149. })
  150. }
  151. }
  152. }
  153. }
  154. })
  155. })
  156. }
  157. // 现app调用方式
  158. const doRequest = (method, url, data)=> {
  159. console.log(method,url,data)
  160. // let baseUrl = config.def().baseUrl
  161. let baseUrl = config.def().baseUrlNew
  162. // 如果data为空
  163. if (!data) var data = []
  164. var arr = []
  165. arr.push(data)
  166. // 接口需要验证的可以将json转成数组添加值再调用
  167. // 不需要的可以直接data:data
  168. return new Promise((resolve, reject) => {
  169. uni.request({
  170. method: method,
  171. url: baseUrl +url,
  172. data: arr[0],
  173. // data:data
  174. header: {
  175. 'content-type': 'application/json'
  176. },
  177. success: function(result) {
  178. // resolve调用后,即可传递到调用方使用then或者async+await同步方式进行处理逻辑
  179. resolve(result)
  180. },
  181. fail: function(e) {
  182. console.log('error in...')
  183. // reject调用后,即可传递到调用方使用catch或者async+await同步方式进行处理逻辑
  184. reject(e)
  185. },
  186. })
  187. })
  188. }
  189. const uploadImg = (successCallback) => {
  190. let baseUrl = config.def().baseUrl
  191. uni.chooseImage({
  192. sizeType: ['compressed'],
  193. success: function(res) {
  194. for (let i = 0; i < res.tempFilePaths.length; i++) {
  195. uni.request({
  196. url: baseUrl + '/upload',
  197. method: 'get',
  198. success: function(signRes) {
  199. uni.showLoading({
  200. title: '图片上传中',
  201. })
  202. let fileName = ('imgs/' + random_string(15) + get_suffix(res.tempFilePaths[i]))
  203. uni.uploadFile({
  204. url: signRes.data.baseUrl,
  205. filePath: res.tempFilePaths[i],
  206. name: 'file',
  207. formData: {
  208. name: res.tempFilePaths[i],
  209. key: fileName,
  210. policy: signRes.data.policy,
  211. OSSAccessKeyId: signRes.data.accessid,
  212. success_action_status: '200',
  213. signature: signRes.data.signature
  214. },
  215. success: function(uploadRes) {
  216. uni.hideLoading()
  217. if (uploadRes.statusCode === 200) {
  218. if (successCallback) {
  219. successCallback(signRes.data.baseUrl + fileName)
  220. } else {
  221. uni.showToast({
  222. title: '上传成功',
  223. icon: 'none'
  224. })
  225. }
  226. } else {
  227. uni.hideLoading()
  228. uni.showToast({
  229. title: '网络错误 code=' + uploadRes.statusCode,
  230. icon: 'none'
  231. })
  232. }
  233. }
  234. })
  235. }
  236. })
  237. }
  238. }
  239. })
  240. }
  241. function get_suffix(filename) {
  242. var pos = filename.lastIndexOf('.')
  243. var suffix = ''
  244. if (pos != -1) {
  245. suffix = filename.substring(pos)
  246. }
  247. return suffix;
  248. }
  249. function random_string(len) {
  250. len = len || 32;
  251. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  252. var maxPos = chars.length;
  253. var pwd = '';
  254. for (var i = 0; i < len; i++) {
  255. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  256. }
  257. return pwd;
  258. }
  259. const prePage = () => {
  260. let pages = getCurrentPages();
  261. let prePage = pages[pages.length - 2];
  262. // #ifdef H5
  263. return prePage;
  264. // #endif
  265. return prePage.$vm;
  266. }
  267. const globalData = {}
  268. Vue.config.productionTip = false
  269. Vue.prototype.$fire = new Vue();
  270. Vue.prototype.$store = store;
  271. Vue.prototype.$api = {
  272. msg,
  273. prePage,
  274. request,
  275. uploadImg,
  276. doRequest,
  277. logout,
  278. isVip,
  279. setUserInfo,
  280. defConfig,
  281. globalData
  282. };
  283. //#ifdef H5
  284. Vue.prototype.$jweixin = jweixin;
  285. //#endif
  286. App.mpType = 'app'
  287. const app = new Vue({
  288. ...App
  289. })
  290. app.$mount()