main.js 7.6 KB

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