main.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  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. //根据经纬度获取地点
  226. const getPlace = (method, url, data, header) => {
  227. var contentheader = 'application/json'
  228. if (header) {
  229. contentheader = header
  230. }
  231. let baseUrl = "https://restapi.amap.com"
  232. return new Promise((resolve, reject) => {
  233. uni.request({
  234. method: method,
  235. url: baseUrl + url,
  236. data: data,
  237. header: {
  238. 'content-type': contentheader
  239. },
  240. success: function(result) {
  241. resolve(result)
  242. },
  243. fail: function(e) {
  244. uni.hideLoading()
  245. console.log('error in...', e)
  246. uni.showToast({
  247. title: e
  248. })
  249. reject(e)
  250. },
  251. })
  252. })
  253. }
  254. // 转换为高德经纬度
  255. const changeLocation = (method, url, data, header) => {
  256. var contentheader = 'application/json'
  257. if (header) {
  258. contentheader = header
  259. }
  260. let baseUrl = "https://restapi.amap.com"
  261. return new Promise((resolve, reject) => {
  262. uni.request({
  263. method: method,
  264. url: baseUrl + url,
  265. data: data,
  266. header: {
  267. 'content-type': contentheader
  268. },
  269. success: function(result) {
  270. resolve(result)
  271. },
  272. fail: function(e) {
  273. uni.hideLoading()
  274. console.log('error in...', e)
  275. uni.showToast({
  276. title: e
  277. })
  278. reject(e)
  279. },
  280. })
  281. })
  282. }
  283. const uploadImg = (successCallback) => {
  284. let baseUrl = config.def().baseUrl
  285. uni.chooseImage({
  286. sizeType: ['compressed'],
  287. success: function(res) {
  288. for (let i = 0; i < res.tempFilePaths.length; i++) {
  289. uni.request({
  290. url: baseUrl + '/upload',
  291. method: 'get',
  292. success: function(signRes) {
  293. uni.showLoading({
  294. title: '图片上传中',
  295. })
  296. let fileName = ('imgs/' + random_string(15) + get_suffix(res
  297. .tempFilePaths[i]))
  298. uni.uploadFile({
  299. url: signRes.data.baseUrl,
  300. filePath: res.tempFilePaths[i],
  301. name: 'file',
  302. formData: {
  303. name: res.tempFilePaths[i],
  304. key: fileName,
  305. policy: signRes.data.policy,
  306. OSSAccessKeyId: signRes.data.accessid,
  307. success_action_status: '200',
  308. signature: signRes.data.signature
  309. },
  310. success: function(uploadRes) {
  311. uni.hideLoading()
  312. if (uploadRes.statusCode === 200) {
  313. if (successCallback) {
  314. successCallback(signRes.data.baseUrl +
  315. fileName)
  316. } else {
  317. uni.showToast({
  318. title: '上传成功',
  319. icon: 'none'
  320. })
  321. }
  322. } else {
  323. uni.hideLoading()
  324. uni.showToast({
  325. title: '网络错误 code=' + uploadRes
  326. .statusCode,
  327. icon: 'none'
  328. })
  329. }
  330. }
  331. })
  332. }
  333. })
  334. }
  335. }
  336. })
  337. }
  338. function get_suffix(filename) {
  339. var pos = filename.lastIndexOf('.')
  340. var suffix = ''
  341. if (pos != -1) {
  342. suffix = filename.substring(pos)
  343. }
  344. return suffix;
  345. }
  346. function random_string(len) {
  347. len = len || 32;
  348. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  349. var maxPos = chars.length;
  350. var pwd = '';
  351. for (var i = 0; i < len; i++) {
  352. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  353. }
  354. return pwd;
  355. }
  356. const prePage = () => {
  357. let pages = getCurrentPages();
  358. let prePage = pages[pages.length - 2];
  359. // #ifdef H5
  360. return prePage;
  361. // #endif
  362. return prePage.$vm;
  363. }
  364. const globalData = {}
  365. Date.prototype.format = function(fmt) {
  366. var o = {
  367. "M+": this.getMonth() + 1, //月份
  368. "d+": this.getDate(), //日
  369. "h+": this.getHours(), //小时
  370. "m+": this.getMinutes(), //分
  371. "s+": this.getSeconds(), //秒
  372. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  373. "S": this.getMilliseconds() //毫秒
  374. };
  375. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  376. for (var k in o)
  377. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : ((
  378. "00" + o[k]).substr(("" + o[k]).length)));
  379. return fmt;
  380. }
  381. Vue.config.productionTip = false
  382. Vue.prototype.$fire = new Vue();
  383. Vue.prototype.$store = store;
  384. Vue.prototype.$api = {
  385. msg,
  386. prePage,
  387. request,
  388. uploadImg,
  389. doRequest,
  390. logout,
  391. isVip,
  392. setUserInfo,
  393. defConfig,
  394. globalData,
  395. getPlace,
  396. changeLocation
  397. };
  398. //#ifdef H5
  399. Vue.prototype.$jweixin = jweixin;
  400. //#endif
  401. App.mpType = 'app'
  402. const app = new Vue({
  403. ...App
  404. })
  405. app.$mount()