main.js 9.0 KB

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