main.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  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. Vue.config.productionTip = false
  22. const vuexStore = require("@/store/$u.mixin.js");
  23. Vue.mixin(vuexStore);
  24. import webim from 'webim.js';
  25. Vue.config.productionTip = false
  26. Vue.prototype.$socket = webim;
  27. App.mpType = 'app'
  28. import * as filters from './filters'
  29. import * as config from './config'
  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. // 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. const request = (_gp, _mt, data = {}, failCallback) => {
  79. //异步请求数据
  80. return new Promise(resolve => {
  81. if (!userInfo || !userInfo.accessToken) {
  82. userInfo = uni.getStorageSync('userInfo')
  83. }
  84. let accessToken = userInfo ? userInfo.accessToken : ''
  85. let baseUrl = config.def().baseUrl
  86. uni.request({
  87. url: baseUrl + '/m.api',
  88. data: {
  89. ...data,
  90. _gp,
  91. _mt
  92. },
  93. method: 'POST',
  94. header: {
  95. 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
  96. 'ACCESSTOKEN': accessToken
  97. },
  98. success: (res) => {
  99. if (res.statusCode === 200) {
  100. if (res.data.errno === 200) {
  101. resolve(res.data);
  102. } else if (res.data.errno === 10001) {
  103. if (failCallback) {
  104. failCallback(res.data)
  105. }
  106. uni.showModal({
  107. title: '登录提示',
  108. content: '您尚未登录,是否立即登录?',
  109. showCancel: true,
  110. confirmText: '登录',
  111. success: (e) => {
  112. if (e.confirm) {
  113. uni.navigateTo({
  114. url: '/pages/public/login'
  115. })
  116. }
  117. },
  118. fail: () => {},
  119. complete: () => {}
  120. })
  121. if (!loginLock) {
  122. loginLock = true
  123. // uni.showModal({
  124. // title: '登录提示',
  125. // content: '您尚未登录,是否立即登录?',
  126. // showCancel: false,
  127. // confirmText: '登录',
  128. // success: (e) => {
  129. // if (e.confirm) {
  130. // uni.navigateTo({
  131. // url: '/pages/public/login'
  132. // })
  133. // }
  134. // },
  135. // fail: () => {},
  136. // complete: () => {
  137. // loginLock = false
  138. // }
  139. // })
  140. }
  141. } else {
  142. if (failCallback) {
  143. failCallback(res.data)
  144. } else {
  145. uni.showToast({
  146. title: res.data.errmsg,
  147. icon: 'none'
  148. })
  149. }
  150. }
  151. }
  152. }
  153. })
  154. })
  155. }
  156. const uploadImg = (successCallback) => {
  157. let baseUrl = config.def().baseUrl
  158. uni.chooseImage({
  159. sizeType: ['compressed'],
  160. success: function(res) {
  161. for (let i = 0; i < res.tempFilePaths.length; i++) {
  162. uni.request({
  163. url: baseUrl + '/upload',
  164. method: 'get',
  165. success: function(signRes) {
  166. uni.showLoading({
  167. title: '图片上传中',
  168. mask:true
  169. })
  170. let fileName = ('imgs/' + random_string(15) + get_suffix(res.tempFilePaths[i]))
  171. uni.uploadFile({
  172. url: signRes.data.baseUrl,
  173. filePath: res.tempFilePaths[i],
  174. name: 'file',
  175. formData: {
  176. name: res.tempFilePaths[i],
  177. key: fileName,
  178. policy: signRes.data.policy,
  179. OSSAccessKeyId: signRes.data.accessid,
  180. success_action_status: '200',
  181. signature: signRes.data.signature
  182. },
  183. success: function(uploadRes) {
  184. uni.hideLoading()
  185. if (uploadRes.statusCode === 200) {
  186. if (successCallback) {
  187. successCallback(signRes.data.baseUrl + fileName)
  188. } else {
  189. uni.showToast({
  190. title: '上传成功',
  191. icon: 'none'
  192. })
  193. }
  194. } else {
  195. uni.hideLoading()
  196. uni.showToast({
  197. title: '网络错误 code=' + uploadRes.statusCode,
  198. icon: 'none'
  199. })
  200. }
  201. }
  202. })
  203. }
  204. })
  205. }
  206. }
  207. })
  208. }
  209. function get_suffix(filename) {
  210. var pos = filename.lastIndexOf('.')
  211. var suffix = ''
  212. if (pos != -1) {
  213. suffix = filename.substring(pos)
  214. }
  215. return suffix;
  216. }
  217. function random_string(len) {
  218. len = len || 32;
  219. var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  220. var maxPos = chars.length;
  221. var pwd = '';
  222. for (var i = 0; i < len; i++) {
  223. pwd += chars.charAt(Math.floor(Math.random() * maxPos));
  224. }
  225. return pwd;
  226. }
  227. const prePage = () => {
  228. let pages = getCurrentPages();
  229. let prePage = pages[pages.length - 2];
  230. // #ifdef H5
  231. return prePage;
  232. // #endif
  233. return prePage.$vm;
  234. }
  235. const globalData = {}
  236. Vue.config.productionTip = false
  237. Vue.prototype.$fire = new Vue();
  238. Vue.prototype.$store = store;
  239. Vue.prototype.$api = {
  240. msg,
  241. prePage,
  242. request,
  243. uploadImg,
  244. logout,
  245. isVip,
  246. setUserInfo,
  247. defConfig,
  248. globalData
  249. };
  250. //#ifdef H5
  251. Vue.prototype.$jweixin = jweixin;
  252. //#endif
  253. App.mpType = 'app'
  254. const app = new Vue({
  255. ...App
  256. })
  257. app.$mount()
  258. /**
  259. * 获取系统权限
  260. * @param {Object} permission 权限标识
  261. * CAMERA: (String 类型 )访问摄像头权限 用于调用摄像头(plus.camera.* plus.barcode.*)
  262. * CONTACTS: (String 类型 )访问系统联系人权限 用于访问(读、写)系统通讯录(plus.gallery.*)
  263. * GALLERY: (String 类型 )访问系统相册权限 用于访问(读、写)系统相册(plus.gallery.*)
  264. * LOCATION: (String 类型 )定位权限 用于获取当前用户位置信息(plus.geolocation.*)
  265. * NOTIFITION: (String 类型 )消息通知权限 用于接收系统消息通知(plus.push.*)
  266. * RECORD: (String 类型 )录音权限 用于进行本地录音操作(plus.audio.AudioRecorder)
  267. * SHORTCUT: (String 类型 )创建桌面快捷方式权限 用于在系统桌面创建快捷方式图标(plus.navigator.createShortcut)
  268. *
  269. * @param {Object} successCallBack 成功回调
  270. * @param {Object} errorCallBack 失败回调
  271. */
  272. function getPermission(permissionIdentity, successCallBack, errorCallBack){
  273. //权限标识转换成大写
  274. var permissionIdentity = permissionIdentity.toUpperCase();
  275. //获取检测权限的状态
  276. var checkResult = plus.navigator.checkPermission(permissionIdentity);
  277. //权限状态是否正常
  278. var permissionStatusOk = false;
  279. //权限中文名称
  280. var permissionName = '';
  281. //对应 andorid 的具体权限
  282. var androidPermission = '';
  283. //获取权限中文意思与对应 android 系统的权限字符串
  284. switch (permissionIdentity) {
  285. case 'CAMERA':
  286. permissionName = '摄像头';
  287. androidPermission = 'android.permission.CAMERA';
  288. break;
  289. case 'CONTACTS':
  290. permissionName = '系统联系人';
  291. androidPermission = 'android.permission.READ_CONTACTS'
  292. break;
  293. case 'GALLERY':
  294. permissionName = '系统相册';
  295. androidPermission = 'android.permission.READ_EXTERNAL_STORAGE';
  296. break;
  297. case 'LOCATION':
  298. permissionName = '定位';
  299. androidPermission = 'android.permission.ACCESS_COARSE_LOCATION';
  300. break;
  301. case 'NOTIFITION':
  302. permissionName = '消息通知';
  303. androidPermission = '消息通知';
  304. break;
  305. case 'RECORD':
  306. permissionName = '录音';
  307. androidPermission = 'android.permission.RECORD_AUDIO';
  308. break;
  309. case 'SHORTCUT':
  310. permissionName = '创建桌面快捷方式';
  311. androidPermission = 'com.android.launcher.permission.INSTALL_SHORTCUT';
  312. break;
  313. default:
  314. permissionName = '未知';
  315. androidPermission = '未知';
  316. break;
  317. }
  318. //判断检查权限的结果
  319. switch (checkResult) {
  320. case 'authorized':
  321. //正常的
  322. permissionStatusOk = true
  323. break;
  324. case 'denied':
  325. //表示程序已被用户拒绝使用此权限,如果是拒绝的就再次提示用户打开确认提示框
  326. //如果有该权限但是没有打开不进行操作还是会去申请或手动打开
  327. // console.log('已关闭' + permissionName + '权限')
  328. // errorCallBack('已关闭' + permissionName + '权限');
  329. // return
  330. break;
  331. case 'undetermined':
  332. // 表示程序未确定是否可使用此权限,此时调用对应的API时系统会弹出提示框让用户确认
  333. // this.requestPermissions(androidPermission, permissionName, successCallBack, errorCallBack)
  334. // errorCallBack('未确定' + permissionName + '权限');
  335. // return
  336. break;
  337. case 'unknown':
  338. errorCallBack('无法查询' + permissionName + '权限');
  339. return
  340. break;
  341. default:
  342. errorCallBack('不支持' + permissionName + '权限');
  343. return
  344. break;
  345. }
  346. //如果权限是正常的执行成功回调
  347. if (permissionStatusOk) {
  348. successCallBack()
  349. } else {
  350. //如果不正常,如果是 andorid 系统,就动态申请权限
  351. if (plus.os.name == 'Android') {
  352. //动态申请权限
  353. plus.android.requestPermissions([androidPermission], function(e) {
  354. if (e.deniedAlways.length > 0) {
  355. //权限被永久拒绝
  356. // 弹出提示框解释为何需要定位权限,引导用户打开设置页面开启
  357. errorCallBack(permissionName + ' 权限被永久拒绝,请到设置权限里找到应用手动开启权限,否则将不能使用此功能。')
  358. // console.log('Always Denied!!! ' + e.deniedAlways.toString());
  359. }
  360. if (e.deniedPresent.length > 0) {
  361. //权限被临时拒绝
  362. // 弹出提示框解释为何需要定位权限,可再次调用plus.android.requestPermissions申请权限
  363. errorCallBack('拒绝开启 ' + permissionName + ' 权限,将不能使用此功能!')
  364. // console.log('Present Denied!!! ' + e.deniedPresent.toString());
  365. }
  366. if (e.granted.length > 0) {
  367. //权限被允许
  368. //调用依赖获取定位权限的代码
  369. successCallBack()
  370. // console.log('Granted!!! ' + e.granted.toString());
  371. }
  372. }, function(e) {
  373. errorCallBack('请求 ' + permissionName + ' 权限失败,' + +JSON.stringify(e))
  374. // console.log('Request Permissions error:' + JSON.stringify(e));
  375. })
  376. } else if (plus.os.name == 'iOS') {
  377. //ios ,第一次使用目的权限时,应用的权限列表里是不存在的,所以先默认执行一下成功回调,打开要使用的操作,比如 plus.camera
  378. //这时系统会提示是否打开相应的权限,如果拒绝也没关系,因为应用的权限列表里已经存在该权限了,下次再调用相应权限时,就会
  379. //走 else 里的流程,会给用户提示,并且跳转到应该的权限页面,让用户手动打开。
  380. if (checkResult == 'undetermined') {
  381. //调用依赖获取定位权限的代码
  382. successCallBack(true)
  383. } else {
  384. //如果是 ios 系统,ios 没有动态申请操作,所以提示用户去设置页面手动打开
  385. mui.confirm(permissionName + ' 权限没有开启,是否去开启?', '提醒', ['取消', '确认'], function(e) {
  386. //取消
  387. if (e.index == 0) {
  388. errorCallBack('拒绝开启 ' + permissionName + ' 权限,将不能使用此功能!')
  389. } else if (e.index == 1) {
  390. //确认,打开当前应用权限设置页面
  391. var UIApplication = plus.ios.import('UIApplication');
  392. var application2 = UIApplication.sharedApplication();
  393. var NSURL2 = plus.ios.import('NSURL');
  394. // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
  395. var setting2 = NSURL2.URLWithString('app-settings:');
  396. application2.openURL(setting2);
  397. plus.ios.deleteObject(setting2);
  398. plus.ios.deleteObject(NSURL2);
  399. plus.ios.deleteObject(application2)
  400. }
  401. }, 'div')
  402. }
  403. }
  404. }
  405. }