main.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  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 appPush from './components/APPPush/index.js'
  17. Vue.use(appPush)
  18. import my from './pages/user/user.vue'
  19. Vue.component('my', my)
  20. // main.js
  21. import uView from "./components/uview-ui";
  22. Vue.use(uView);
  23. const vuexStore = require("@/store/$u.mixin.js");
  24. import helper from '@/common/helper.js'
  25. Vue.prototype.$helper = helper
  26. Vue.mixin(vuexStore);
  27. import webim from 'webim.js';
  28. Vue.config.productionTip = false
  29. Vue.prototype.$socket = webim;
  30. App.mpType = 'app'
  31. import * as filters from './filters'
  32. import * as config from './config'
  33. import utils from '@/util/util.js'
  34. import '@/common/directive.js'
  35. let urlAddress = 'liangxin.zthymaoyi.com'
  36. Vue.prototype.$url = 'https://' + urlAddress + '/upload/'
  37. Vue.prototype.$uploadUrl = config.def().baseUrlNew + 'appendix/api/uploadFiles'
  38. Vue.prototype.$ws = 'wss://' + urlAddress + '/chat'
  39. Vue.prototype.$ossUrl = 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/'
  40. Vue.prototype.utils = utils
  41. // 注册全局组件
  42. import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue"
  43. import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue"
  44. Vue.component('mescroll-body', MescrollBody)
  45. Vue.component('mescroll-uni', MescrollUni)
  46. // let urlAddress = 'localhost'
  47. // Vue.prototype.$url = 'https://liangxin.zthymaoyi.com/upload/'
  48. // Vue.prototype.$uploadUrl = 'https://liangxin.zthymaoyi.com/file/upload'
  49. // Vue.prototype.$ws = 'ws://'+urlAddress+':9999/chat'
  50. Object.keys(filters).forEach(key => {
  51. Vue.filter(key, filters[key])
  52. })
  53. //#ifdef H5
  54. let jweixin = require('./components/jweixin-module')
  55. let jwx = require('./components/jweixin-module/jwx')
  56. Vue.mixin({
  57. onShow() {
  58. jwx.configWeiXin(jwx => {})
  59. }
  60. })
  61. //#endif
  62. const defConfig = config.def
  63. const msg = (title, duration = 3500, mask = false, icon = 'none') => {
  64. //统一提示方便全局修改
  65. if (Boolean(title) === false) {
  66. return;
  67. }
  68. uni.showToast({
  69. title,
  70. duration,
  71. mask,
  72. icon
  73. });
  74. }
  75. let userInfo = undefined
  76. const logout = () => {
  77. userInfo = undefined
  78. uni.removeStorage({
  79. key: 'userInfo'
  80. })
  81. uni.removeStorage({
  82. key: 'rolesList'
  83. })
  84. uni.removeStorage({
  85. key: 'jurisdiction'
  86. })
  87. }
  88. const setUserInfo = (i) => {
  89. userInfo = i
  90. }
  91. const isVip = () => {
  92. return userInfo && userInfo.level
  93. }
  94. let loginLock = false
  95. // 原微信小程序请求方式
  96. const request = (_gp, _mt, data = {}, failCallback) => {
  97. //异步请求数据
  98. return new Promise(resolve => {
  99. if (!userInfo || !userInfo.accessToken) {
  100. userInfo = uni.getStorageSync('userInfo')
  101. }
  102. let accessToken = userInfo ? userInfo.accessToken : ''
  103. // let baseUrl = 'http://192.168.1.120:8090/'
  104. let baseUrl = config.def().baseUrl
  105. uni.request({
  106. url: baseUrl + '/m.api',
  107. data: {
  108. ...data,
  109. _gp,
  110. _mt
  111. },
  112. method: 'POST',
  113. header: {
  114. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  115. 'ACCESSTOKEN': accessToken
  116. },
  117. success: (res) => {
  118. if (res.statusCode === 200) {
  119. if (res.data.errno === 200) {
  120. resolve(res.data);
  121. } else if (res.data.errno === 10001) {
  122. if (failCallback) {
  123. failCallback(res.data)
  124. }
  125. uni.showModal({
  126. title: '提示',
  127. content: '您尚未登录,是否立即登录?',
  128. showCancel: true,
  129. confirmText: '登录',
  130. success: (e) => {
  131. if (e.confirm) {
  132. uni.navigateTo({
  133. url: '/pages/public/login'
  134. })
  135. }
  136. },
  137. fail: () => {},
  138. complete: () => {}
  139. })
  140. if (!loginLock) {
  141. loginLock = true
  142. // uni.showModal({
  143. // title: '提示',
  144. // content: '您尚未登录,是否立即登录?',
  145. // showCancel: false,
  146. // confirmText: '登录',
  147. // success: (e) => {
  148. // if (e.confirm) {
  149. // uni.navigateTo({
  150. // url: '/pages/public/login'
  151. // })
  152. // }
  153. // },
  154. // fail: () => {},
  155. // complete: () => {
  156. // loginLock = false
  157. // }
  158. // })
  159. }
  160. } else {
  161. if (failCallback) {
  162. failCallback(res.data)
  163. } else {
  164. if (res.data.errmsg) {
  165. uni.showToast({
  166. title: res.data.errmsg,
  167. icon: 'none',
  168. duration: 2000
  169. })
  170. } else {
  171. uni.showToast({
  172. title: "系统异常,请联系管理员",
  173. icon: 'none',
  174. duration: 2000
  175. })
  176. }
  177. }
  178. }
  179. }
  180. }
  181. })
  182. })
  183. }
  184. // 现app调用方式
  185. const doRequest = (method, url, data, header) => {
  186. var contentheader = 'application/json'
  187. if (header) {
  188. contentheader = header
  189. }
  190. // let baseUrl = config.def().baseUrl
  191. let baseUrl = config.def().baseUrlNew
  192. // 如果data为空
  193. // if (!data) var data = []
  194. // var arr = []
  195. // arr.push(data)
  196. // 接口需要验证的可以将json转成数组添加值再调用
  197. // 不需要的可以直接data:data
  198. return new Promise((resolve, reject) => {
  199. uni.request({
  200. method: method,
  201. url: baseUrl + url,
  202. // data: arr[0],
  203. data: data,
  204. header: {
  205. 'content-type': contentheader //'application/x-www-form-urlencoded; charset=UTF-8',
  206. },
  207. success: function(result) {
  208. // console.log(result,111111111111)
  209. // uni.hideLoading()
  210. resolve(result)
  211. // resolve调用后,即可传递到调用方使用then或者async+await同步方式进行处理逻辑
  212. },
  213. fail: function(e) {
  214. uni.hideLoading()
  215. console.log('error in...', e)
  216. uni.showToast({
  217. title: e
  218. })
  219. // reject调用后,即可传递到调用方使用catch或者async+await同步方式进行处理逻辑
  220. reject(e)
  221. },
  222. })
  223. })
  224. }
  225. const uploadImg = (successCallback) => {
  226. let baseUrl = config.def().baseUrl
  227. uni.chooseImage({
  228. sizeType: ['compressed'],
  229. success: function(res) {
  230. for (let i = 0; i < res.tempFilePaths.length; i++) {
  231. uni.request({
  232. url: baseUrl + '/upload',
  233. method: 'get',
  234. success: function(signRes) {
  235. uni.showLoading({
  236. title: '图片上传中',
  237. })
  238. let fileName = ('imgs/' + random_string(15) + get_suffix(res
  239. .tempFilePaths[i]))
  240. uni.uploadFile({
  241. url: signRes.data.baseUrl,
  242. filePath: res.tempFilePaths[i],
  243. name: 'file',
  244. formData: {
  245. name: res.tempFilePaths[i],
  246. key: fileName,
  247. policy: signRes.data.policy,
  248. OSSAccessKeyId: signRes.data.accessid,
  249. success_action_status: '200',
  250. signature: signRes.data.signature
  251. },
  252. success: function(uploadRes) {
  253. uni.hideLoading()
  254. if (uploadRes.statusCode === 200) {
  255. if (successCallback) {
  256. successCallback(signRes.data.baseUrl +
  257. fileName)
  258. } else {
  259. uni.showToast({
  260. title: '上传成功',
  261. icon: 'none'
  262. })
  263. }
  264. } else {
  265. uni.hideLoading()
  266. uni.showToast({
  267. title: '网络错误 code=' + uploadRes
  268. .statusCode,
  269. icon: 'none'
  270. })
  271. }
  272. }
  273. })
  274. }
  275. })
  276. }
  277. }
  278. })
  279. }
  280. function get_suffix(filename) {
  281. var pos = filename.lastIndexOf('.')
  282. var suffix = ''
  283. if (pos != -1) {
  284. suffix = filename.substring(pos)
  285. }
  286. return suffix;
  287. }
  288. function random_string(len) {
  289. len = len || 32;
  290. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  291. var maxPos = chars.length;
  292. var pwd = '';
  293. for (var i = 0; i < len; i++) {
  294. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  295. }
  296. return pwd;
  297. }
  298. const prePage = () => {
  299. let pages = getCurrentPages();
  300. let prePage = pages[pages.length - 2];
  301. // #ifdef H5
  302. return prePage;
  303. // #endif
  304. return prePage.$vm;
  305. }
  306. const globalData = {}
  307. Date.prototype.format = function(fmt) {
  308. var o = {
  309. "M+": this.getMonth() + 1, //月份
  310. "d+": this.getDate(), //日
  311. "h+": this.getHours(), //小时
  312. "m+": this.getMinutes(), //分
  313. "s+": this.getSeconds(), //秒
  314. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  315. "S": this.getMilliseconds() //毫秒
  316. };
  317. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  318. for (var k in o)
  319. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : ((
  320. "00" + o[k]).substr(("" + o[k]).length)));
  321. return fmt;
  322. }
  323. Vue.config.productionTip = false
  324. Vue.prototype.$fire = new Vue();
  325. Vue.prototype.$store = store;
  326. Vue.prototype.$api = {
  327. msg,
  328. prePage,
  329. request,
  330. uploadImg,
  331. doRequest,
  332. logout,
  333. isVip,
  334. setUserInfo,
  335. defConfig,
  336. globalData
  337. };
  338. //#ifdef H5
  339. Vue.prototype.$jweixin = jweixin;
  340. //#endif
  341. App.mpType = 'app'
  342. const app = new Vue({
  343. ...App
  344. })
  345. app.$mount()