main.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. if(res.data.errmsg){
  150. uni.showToast({
  151. title: res.data.errmsg,
  152. icon: 'none',
  153. duration: 2000
  154. })
  155. }
  156. else{
  157. uni.showToast({
  158. title: "系统异常,请联系管理员",
  159. icon: 'none',
  160. duration: 2000
  161. })
  162. }
  163. }
  164. }
  165. }
  166. }
  167. })
  168. })
  169. }
  170. // 现app调用方式
  171. const doRequest = (method, url, data,header)=> {
  172. var contentheader='application/json'
  173. if(header){
  174. contentheader=header
  175. }
  176. // let baseUrl = config.def().baseUrl
  177. let baseUrl = config.def().baseUrlNew
  178. // 如果data为空
  179. // if (!data) var data = []
  180. // var arr = []
  181. // arr.push(data)
  182. // 接口需要验证的可以将json转成数组添加值再调用
  183. // 不需要的可以直接data:data
  184. return new Promise((resolve, reject) => {
  185. uni.request({
  186. method: method,
  187. url: baseUrl +url,
  188. // data: arr[0],
  189. data:data,
  190. header: {
  191. 'content-type': contentheader //'application/x-www-form-urlencoded; charset=UTF-8',
  192. },
  193. success: function(result) {
  194. // resolve调用后,即可传递到调用方使用then或者async+await同步方式进行处理逻辑
  195. resolve(result)
  196. },
  197. fail: function(e) {
  198. console.log('error in...',e)
  199. uni.showToast({
  200. title:e
  201. })
  202. // reject调用后,即可传递到调用方使用catch或者async+await同步方式进行处理逻辑
  203. reject(e)
  204. },
  205. })
  206. })
  207. }
  208. const uploadImg = (successCallback) => {
  209. let baseUrl = config.def().baseUrl
  210. uni.chooseImage({
  211. sizeType: ['compressed'],
  212. success: function(res) {
  213. for (let i = 0; i < res.tempFilePaths.length; i++) {
  214. uni.request({
  215. url: baseUrl + '/upload',
  216. method: 'get',
  217. success: function(signRes) {
  218. uni.showLoading({
  219. title: '图片上传中',
  220. })
  221. let fileName = ('imgs/' + random_string(15) + get_suffix(res.tempFilePaths[i]))
  222. uni.uploadFile({
  223. url: signRes.data.baseUrl,
  224. filePath: res.tempFilePaths[i],
  225. name: 'file',
  226. formData: {
  227. name: res.tempFilePaths[i],
  228. key: fileName,
  229. policy: signRes.data.policy,
  230. OSSAccessKeyId: signRes.data.accessid,
  231. success_action_status: '200',
  232. signature: signRes.data.signature
  233. },
  234. success: function(uploadRes) {
  235. uni.hideLoading()
  236. if (uploadRes.statusCode === 200) {
  237. if (successCallback) {
  238. successCallback(signRes.data.baseUrl + fileName)
  239. } else {
  240. uni.showToast({
  241. title: '上传成功',
  242. icon: 'none'
  243. })
  244. }
  245. } else {
  246. uni.hideLoading()
  247. uni.showToast({
  248. title: '网络错误 code=' + uploadRes.statusCode,
  249. icon: 'none'
  250. })
  251. }
  252. }
  253. })
  254. }
  255. })
  256. }
  257. }
  258. })
  259. }
  260. function get_suffix(filename) {
  261. var pos = filename.lastIndexOf('.')
  262. var suffix = ''
  263. if (pos != -1) {
  264. suffix = filename.substring(pos)
  265. }
  266. return suffix;
  267. }
  268. function random_string(len) {
  269. len = len || 32;
  270. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  271. var maxPos = chars.length;
  272. var pwd = '';
  273. for (var i = 0; i < len; i++) {
  274. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  275. }
  276. return pwd;
  277. }
  278. const prePage = () => {
  279. let pages = getCurrentPages();
  280. let prePage = pages[pages.length - 2];
  281. // #ifdef H5
  282. return prePage;
  283. // #endif
  284. return prePage.$vm;
  285. }
  286. const globalData = {}
  287. Vue.config.productionTip = false
  288. Vue.prototype.$fire = new Vue();
  289. Vue.prototype.$store = store;
  290. Vue.prototype.$api = {
  291. msg,
  292. prePage,
  293. request,
  294. uploadImg,
  295. doRequest,
  296. logout,
  297. isVip,
  298. setUserInfo,
  299. defConfig,
  300. globalData
  301. };
  302. //#ifdef H5
  303. Vue.prototype.$jweixin = jweixin;
  304. //#endif
  305. App.mpType = 'app'
  306. const app = new Vue({
  307. ...App
  308. })
  309. app.$mount()