main.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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,header)=> {
  159. var contentheader='application/json'
  160. if(header){
  161. contentheader=header
  162. }
  163. // let baseUrl = config.def().baseUrl
  164. let baseUrl = config.def().baseUrlNew
  165. // 如果data为空
  166. // if (!data) var data = []
  167. // var arr = []
  168. // arr.push(data)
  169. // 接口需要验证的可以将json转成数组添加值再调用
  170. // 不需要的可以直接data:data
  171. return new Promise((resolve, reject) => {
  172. uni.request({
  173. method: method,
  174. url: baseUrl +url,
  175. // data: arr[0],
  176. data:data,
  177. header: {
  178. 'content-type': contentheader //'application/x-www-form-urlencoded; charset=UTF-8',
  179. },
  180. success: function(result) {
  181. // resolve调用后,即可传递到调用方使用then或者async+await同步方式进行处理逻辑
  182. resolve(result)
  183. },
  184. fail: function(e) {
  185. console.log('error in...')
  186. // reject调用后,即可传递到调用方使用catch或者async+await同步方式进行处理逻辑
  187. reject(e)
  188. },
  189. })
  190. })
  191. }
  192. const uploadImg = (successCallback) => {
  193. let baseUrl = config.def().baseUrl
  194. uni.chooseImage({
  195. sizeType: ['compressed'],
  196. success: function(res) {
  197. for (let i = 0; i < res.tempFilePaths.length; i++) {
  198. uni.request({
  199. url: baseUrl + '/upload',
  200. method: 'get',
  201. success: function(signRes) {
  202. uni.showLoading({
  203. title: '图片上传中',
  204. })
  205. let fileName = ('imgs/' + random_string(15) + get_suffix(res.tempFilePaths[i]))
  206. uni.uploadFile({
  207. url: signRes.data.baseUrl,
  208. filePath: res.tempFilePaths[i],
  209. name: 'file',
  210. formData: {
  211. name: res.tempFilePaths[i],
  212. key: fileName,
  213. policy: signRes.data.policy,
  214. OSSAccessKeyId: signRes.data.accessid,
  215. success_action_status: '200',
  216. signature: signRes.data.signature
  217. },
  218. success: function(uploadRes) {
  219. uni.hideLoading()
  220. if (uploadRes.statusCode === 200) {
  221. if (successCallback) {
  222. successCallback(signRes.data.baseUrl + fileName)
  223. } else {
  224. uni.showToast({
  225. title: '上传成功',
  226. icon: 'none'
  227. })
  228. }
  229. } else {
  230. uni.hideLoading()
  231. uni.showToast({
  232. title: '网络错误 code=' + uploadRes.statusCode,
  233. icon: 'none'
  234. })
  235. }
  236. }
  237. })
  238. }
  239. })
  240. }
  241. }
  242. })
  243. }
  244. function get_suffix(filename) {
  245. var pos = filename.lastIndexOf('.')
  246. var suffix = ''
  247. if (pos != -1) {
  248. suffix = filename.substring(pos)
  249. }
  250. return suffix;
  251. }
  252. function random_string(len) {
  253. len = len || 32;
  254. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  255. var maxPos = chars.length;
  256. var pwd = '';
  257. for (var i = 0; i < len; i++) {
  258. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  259. }
  260. return pwd;
  261. }
  262. const prePage = () => {
  263. let pages = getCurrentPages();
  264. let prePage = pages[pages.length - 2];
  265. // #ifdef H5
  266. return prePage;
  267. // #endif
  268. return prePage.$vm;
  269. }
  270. const globalData = {}
  271. Vue.config.productionTip = false
  272. Vue.prototype.$fire = new Vue();
  273. Vue.prototype.$store = store;
  274. Vue.prototype.$api = {
  275. msg,
  276. prePage,
  277. request,
  278. uploadImg,
  279. doRequest,
  280. logout,
  281. isVip,
  282. setUserInfo,
  283. defConfig,
  284. globalData
  285. };
  286. //#ifdef H5
  287. Vue.prototype.$jweixin = jweixin;
  288. //#endif
  289. App.mpType = 'app'
  290. const app = new Vue({
  291. ...App
  292. })
  293. app.$mount()