main.js 8.7 KB

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