123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436 |
- import Vue from 'vue'
- import store from './store'
- import App from './App'
- import share from './common/share.js'
- Vue.mixin(share)
- import cuCustom from './components/colorui/components/cu-custom.vue';
- Vue.component('cu-custom',cuCustom)
- import buy from './pages/buy/transaction.vue'
- Vue.component('buy',buy)
- import sale from './pages/sale/information.vue'
- Vue.component('sale',sale)
- import tarBar from './components/tarbar.vue'
- Vue.component('tar-bar', tarBar)
- import tran from './pages/tran/tran.vue'
- Vue.component('tran',tran)
- import my from './pages/user/user.vue'
- Vue.component('my',my)
- // main.js
- import uView from "./components/uview-ui";
- Vue.use(uView);
- Vue.config.productionTip = false
- const vuexStore = require("@/store/$u.mixin.js");
- Vue.mixin(vuexStore);
- import webim from 'webim.js';
- Vue.config.productionTip = false
- Vue.prototype.$socket = webim;
- App.mpType = 'app'
- import * as filters from './filters'
- import * as config from './config'
- let urlAddress = 'liangxin.zthymaoyi.com'
- Vue.prototype.$url = 'https://'+urlAddress+'/upload/'
- Vue.prototype.$uploadUrl = 'https://'+urlAddress+'/file/upload'
- Vue.prototype.$ws = 'wss://'+urlAddress+'/chat'
- // let urlAddress = 'localhost'
- // Vue.prototype.$url = 'https://liangxin.zthymaoyi.com/upload/'
- // Vue.prototype.$uploadUrl = 'https://liangxin.zthymaoyi.com/file/upload'
- // Vue.prototype.$ws = 'ws://'+urlAddress+':9999/chat'
- Object.keys(filters).forEach(key => {
- Vue.filter(key, filters[key])
- })
- //#ifdef H5
- let jweixin = require('./components/jweixin-module')
- let jwx = require('./components/jweixin-module/jwx')
- Vue.mixin({
- onShow() {
- jwx.configWeiXin(jwx => {
- })
- }
- })
- //#endif
- const defConfig = config.def
- const msg = (title, duration = 3500, mask = false, icon = 'none') => {
- //统一提示方便全局修改
- if (Boolean(title) === false) {
- return;
- }
- uni.showToast({
- title,
- duration,
- mask,
- icon
- });
- }
- let userInfo = undefined
- const logout = () => {
- userInfo = undefined
- uni.removeStorage({
- key: 'userInfo'
- })
- }
- const setUserInfo = (i) => {
- userInfo = i
- }
- const isVip = () => {
- return userInfo && userInfo.level
- }
- let loginLock = false
- const request = (_gp, _mt, data = {}, failCallback) => {
- //异步请求数据
- return new Promise(resolve => {
- if (!userInfo || !userInfo.accessToken) {
- userInfo = uni.getStorageSync('userInfo')
- }
- let accessToken = userInfo ? userInfo.accessToken : ''
- let baseUrl = config.def().baseUrl
- uni.request({
- url: baseUrl + '/m.api',
- data: {
- ...data,
- _gp,
- _mt
- },
- method: 'POST',
- header: {
- 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
- 'ACCESSTOKEN': accessToken
- },
- success: (res) => {
- if (res.statusCode === 200) {
- if (res.data.errno === 200) {
- resolve(res.data);
- } else if (res.data.errno === 10001) {
- if (failCallback) {
- failCallback(res.data)
- }
- uni.showModal({
- title: '登录提示',
- content: '您尚未登录,是否立即登录?',
- showCancel: true,
- confirmText: '登录',
- success: (e) => {
- if (e.confirm) {
- uni.navigateTo({
- url: '/pages/public/login'
- })
- }
- },
- fail: () => {},
- complete: () => {}
- })
- if (!loginLock) {
- loginLock = true
- // uni.showModal({
- // title: '登录提示',
- // content: '您尚未登录,是否立即登录?',
- // showCancel: false,
- // confirmText: '登录',
- // success: (e) => {
- // if (e.confirm) {
- // uni.navigateTo({
- // url: '/pages/public/login'
- // })
- // }
- // },
- // fail: () => {},
- // complete: () => {
- // loginLock = false
- // }
- // })
- }
- } else {
- if (failCallback) {
- failCallback(res.data)
- } else {
- uni.showToast({
- title: res.data.errmsg,
- icon: 'none'
- })
- }
- }
- }
- }
- })
- })
- }
- const uploadImg = (successCallback) => {
- let baseUrl = config.def().baseUrl
- uni.chooseImage({
- sizeType: ['compressed'],
- success: function(res) {
- for (let i = 0; i < res.tempFilePaths.length; i++) {
- uni.request({
- url: baseUrl + '/upload',
- method: 'get',
- success: function(signRes) {
- uni.showLoading({
- title: '图片上传中',
- mask:true
- })
- let fileName = ('imgs/' + random_string(15) + get_suffix(res.tempFilePaths[i]))
- uni.uploadFile({
- url: signRes.data.baseUrl,
- filePath: res.tempFilePaths[i],
- name: 'file',
- formData: {
- name: res.tempFilePaths[i],
- key: fileName,
- policy: signRes.data.policy,
- OSSAccessKeyId: signRes.data.accessid,
- success_action_status: '200',
- signature: signRes.data.signature
- },
- success: function(uploadRes) {
- uni.hideLoading()
- if (uploadRes.statusCode === 200) {
- if (successCallback) {
- successCallback(signRes.data.baseUrl + fileName)
- } else {
- uni.showToast({
- title: '上传成功',
- icon: 'none'
- })
- }
- } else {
- uni.hideLoading()
- uni.showToast({
- title: '网络错误 code=' + uploadRes.statusCode,
- icon: 'none'
- })
- }
- }
- })
- }
- })
- }
- }
- })
- }
- function get_suffix(filename) {
- var pos = filename.lastIndexOf('.')
- var suffix = ''
- if (pos != -1) {
- suffix = filename.substring(pos)
- }
- return suffix;
- }
- function random_string(len) {
- len = len || 32;
- var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
- var maxPos = chars.length;
- var pwd = '';
- for (var i = 0; i < len; i++) {
- pwd += chars.charAt(Math.floor(Math.random() * maxPos));
- }
- return pwd;
- }
- const prePage = () => {
- let pages = getCurrentPages();
- let prePage = pages[pages.length - 2];
- // #ifdef H5
- return prePage;
- // #endif
- return prePage.$vm;
- }
- const globalData = {}
- Vue.config.productionTip = false
- Vue.prototype.$fire = new Vue();
- Vue.prototype.$store = store;
- Vue.prototype.$api = {
- msg,
- prePage,
- request,
- uploadImg,
- logout,
- isVip,
- setUserInfo,
- defConfig,
- globalData
- };
- //#ifdef H5
- Vue.prototype.$jweixin = jweixin;
- //#endif
- App.mpType = 'app'
- const app = new Vue({
- ...App
- })
- app.$mount()
- /**
- * 获取系统权限
- * @param {Object} permission 权限标识
- * CAMERA: (String 类型 )访问摄像头权限 用于调用摄像头(plus.camera.* plus.barcode.*)
- * CONTACTS: (String 类型 )访问系统联系人权限 用于访问(读、写)系统通讯录(plus.gallery.*)
- * GALLERY: (String 类型 )访问系统相册权限 用于访问(读、写)系统相册(plus.gallery.*)
- * LOCATION: (String 类型 )定位权限 用于获取当前用户位置信息(plus.geolocation.*)
- * NOTIFITION: (String 类型 )消息通知权限 用于接收系统消息通知(plus.push.*)
- * RECORD: (String 类型 )录音权限 用于进行本地录音操作(plus.audio.AudioRecorder)
- * SHORTCUT: (String 类型 )创建桌面快捷方式权限 用于在系统桌面创建快捷方式图标(plus.navigator.createShortcut)
- *
- * @param {Object} successCallBack 成功回调
- * @param {Object} errorCallBack 失败回调
- */
- function getPermission(permissionIdentity, successCallBack, errorCallBack){
- //权限标识转换成大写
- var permissionIdentity = permissionIdentity.toUpperCase();
- //获取检测权限的状态
- var checkResult = plus.navigator.checkPermission(permissionIdentity);
- //权限状态是否正常
- var permissionStatusOk = false;
- //权限中文名称
- var permissionName = '';
- //对应 andorid 的具体权限
- var androidPermission = '';
- //获取权限中文意思与对应 android 系统的权限字符串
- switch (permissionIdentity) {
- case 'CAMERA':
- permissionName = '摄像头';
- androidPermission = 'android.permission.CAMERA';
- break;
- case 'CONTACTS':
- permissionName = '系统联系人';
- androidPermission = 'android.permission.READ_CONTACTS'
- break;
- case 'GALLERY':
- permissionName = '系统相册';
- androidPermission = 'android.permission.READ_EXTERNAL_STORAGE';
- break;
- case 'LOCATION':
- permissionName = '定位';
- androidPermission = 'android.permission.ACCESS_COARSE_LOCATION';
- break;
- case 'NOTIFITION':
- permissionName = '消息通知';
- androidPermission = '消息通知';
- break;
- case 'RECORD':
- permissionName = '录音';
- androidPermission = 'android.permission.RECORD_AUDIO';
- break;
- case 'SHORTCUT':
- permissionName = '创建桌面快捷方式';
- androidPermission = 'com.android.launcher.permission.INSTALL_SHORTCUT';
- break;
- default:
- permissionName = '未知';
- androidPermission = '未知';
- break;
- }
- //判断检查权限的结果
- switch (checkResult) {
- case 'authorized':
- //正常的
- permissionStatusOk = true
- break;
- case 'denied':
- //表示程序已被用户拒绝使用此权限,如果是拒绝的就再次提示用户打开确认提示框
- //如果有该权限但是没有打开不进行操作还是会去申请或手动打开
- // console.log('已关闭' + permissionName + '权限')
- // errorCallBack('已关闭' + permissionName + '权限');
- // return
- break;
- case 'undetermined':
- // 表示程序未确定是否可使用此权限,此时调用对应的API时系统会弹出提示框让用户确认
- // this.requestPermissions(androidPermission, permissionName, successCallBack, errorCallBack)
- // errorCallBack('未确定' + permissionName + '权限');
- // return
- break;
- case 'unknown':
- errorCallBack('无法查询' + permissionName + '权限');
- return
- break;
- default:
- errorCallBack('不支持' + permissionName + '权限');
- return
- break;
- }
- //如果权限是正常的执行成功回调
- if (permissionStatusOk) {
- successCallBack()
- } else {
- //如果不正常,如果是 andorid 系统,就动态申请权限
- if (plus.os.name == 'Android') {
- //动态申请权限
- plus.android.requestPermissions([androidPermission], function(e) {
- if (e.deniedAlways.length > 0) {
- //权限被永久拒绝
- // 弹出提示框解释为何需要定位权限,引导用户打开设置页面开启
- errorCallBack(permissionName + ' 权限被永久拒绝,请到设置权限里找到应用手动开启权限,否则将不能使用此功能。')
- // console.log('Always Denied!!! ' + e.deniedAlways.toString());
- }
- if (e.deniedPresent.length > 0) {
- //权限被临时拒绝
- // 弹出提示框解释为何需要定位权限,可再次调用plus.android.requestPermissions申请权限
- errorCallBack('拒绝开启 ' + permissionName + ' 权限,将不能使用此功能!')
- // console.log('Present Denied!!! ' + e.deniedPresent.toString());
- }
- if (e.granted.length > 0) {
- //权限被允许
- //调用依赖获取定位权限的代码
- successCallBack()
- // console.log('Granted!!! ' + e.granted.toString());
- }
- }, function(e) {
- errorCallBack('请求 ' + permissionName + ' 权限失败,' + +JSON.stringify(e))
- // console.log('Request Permissions error:' + JSON.stringify(e));
- })
- } else if (plus.os.name == 'iOS') {
- //ios ,第一次使用目的权限时,应用的权限列表里是不存在的,所以先默认执行一下成功回调,打开要使用的操作,比如 plus.camera
- //这时系统会提示是否打开相应的权限,如果拒绝也没关系,因为应用的权限列表里已经存在该权限了,下次再调用相应权限时,就会
- //走 else 里的流程,会给用户提示,并且跳转到应该的权限页面,让用户手动打开。
- if (checkResult == 'undetermined') {
- //调用依赖获取定位权限的代码
- successCallBack(true)
- } else {
- //如果是 ios 系统,ios 没有动态申请操作,所以提示用户去设置页面手动打开
- mui.confirm(permissionName + ' 权限没有开启,是否去开启?', '提醒', ['取消', '确认'], function(e) {
- //取消
- if (e.index == 0) {
- errorCallBack('拒绝开启 ' + permissionName + ' 权限,将不能使用此功能!')
- } else if (e.index == 1) {
- //确认,打开当前应用权限设置页面
- var UIApplication = plus.ios.import('UIApplication');
- var application2 = UIApplication.sharedApplication();
- var NSURL2 = plus.ios.import('NSURL');
- // var setting2 = NSURL2.URLWithString("prefs:root=LOCATION_SERVICES");
- var setting2 = NSURL2.URLWithString('app-settings:');
- application2.openURL(setting2);
- plus.ios.deleteObject(setting2);
- plus.ios.deleteObject(NSURL2);
- plus.ios.deleteObject(application2)
- }
- }, 'div')
- }
- }
- }
- }
|