main.js 8.0 KB

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