main.js 7.7 KB

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