main.js 8.9 KB

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