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 appPush from './components/APPPush/index.js' Vue.use(appPush) import my from './pages/user/user.vue' Vue.component('my', my) // main.js import uView from "./components/uview-ui"; Vue.use(uView); const vuexStore = require("@/store/$u.mixin.js"); import helper from '@/common/helper.js' Vue.prototype.$helper = helper 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' import utils from '@/util/util.js' import '@/common/directive.js' let urlAddress = 'liangxin.zthymaoyi.com' Vue.prototype.$url = 'https://' + urlAddress + '/upload/' Vue.prototype.$uploadUrl = config.def().baseUrlNew + 'appendix/api/uploadFiles' Vue.prototype.$ws = 'wss://' + urlAddress + '/chat' Vue.prototype.$ossUrl = 'https://taohaoliang.oss-cn-beijing.aliyuncs.com/' Vue.prototype.utils = utils // 注册全局组件 import MescrollBody from "@/components/mescroll-uni/mescroll-body.vue" import MescrollUni from "@/components/mescroll-uni/mescroll-uni.vue" Vue.component('mescroll-body', MescrollBody) Vue.component('mescroll-uni', MescrollUni) // 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' }) uni.removeStorage({ key: 'rolesList' }) uni.removeStorage({ key: 'jurisdiction' }) } 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 = 'http://192.168.1.120:8090/' 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 { if (res.data.errmsg) { uni.showToast({ title: res.data.errmsg, icon: 'none', duration: 2000 }) } else { uni.showToast({ title: "系统异常,请联系管理员", icon: 'none', duration: 2000 }) } } } } } }) }) } // 现app调用方式 const doRequest = (method, url, data, header) => { var contentheader = 'application/json' if (header) { contentheader = header } // let baseUrl = config.def().baseUrl let baseUrl = config.def().baseUrlNew // 如果data为空 // if (!data) var data = [] // var arr = [] // arr.push(data) // 接口需要验证的可以将json转成数组添加值再调用 // 不需要的可以直接data:data return new Promise((resolve, reject) => { uni.request({ method: method, url: baseUrl + url, // data: arr[0], data: data, header: { 'content-type': contentheader //'application/x-www-form-urlencoded; charset=UTF-8', }, success: function(result) { // console.log(result,111111111111) // uni.hideLoading() resolve(result) // resolve调用后,即可传递到调用方使用then或者async+await同步方式进行处理逻辑 }, fail: function(e) { uni.hideLoading() console.log('error in...', e) uni.showToast({ title: e }) // reject调用后,即可传递到调用方使用catch或者async+await同步方式进行处理逻辑 reject(e) }, }) }) } //根据经纬度获取地点 const getPlace = (method, url, data, header) => { var contentheader = 'application/json' if (header) { contentheader = header } let baseUrl = "https://restapi.amap.com" return new Promise((resolve, reject) => { uni.request({ method: method, url: baseUrl + url, data: data, header: { 'content-type': contentheader }, success: function(result) { resolve(result) }, fail: function(e) { uni.hideLoading() console.log('error in...', e) uni.showToast({ title: e }) reject(e) }, }) }) } // 转换为高德经纬度 const changeLocation = (method, url, data, header) => { var contentheader = 'application/json' if (header) { contentheader = header } let baseUrl = "https://restapi.amap.com" return new Promise((resolve, reject) => { uni.request({ method: method, url: baseUrl + url, data: data, header: { 'content-type': contentheader }, success: function(result) { resolve(result) }, fail: function(e) { uni.hideLoading() console.log('error in...', e) uni.showToast({ title: e }) reject(e) }, }) }) } 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: '图片上传中', }) 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 = {} Date.prototype.format = function(fmt) { var o = { "M+": this.getMonth() + 1, //月份 "d+": this.getDate(), //日 "h+": this.getHours(), //小时 "m+": this.getMinutes(), //分 "s+": this.getSeconds(), //秒 "q+": Math.floor((this.getMonth() + 3) / 3), //季度 "S": this.getMilliseconds() //毫秒 }; if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length)); for (var k in o) if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (( "00" + o[k]).substr(("" + o[k]).length))); return fmt; } Vue.config.productionTip = false Vue.prototype.$fire = new Vue(); Vue.prototype.$store = store; Vue.prototype.$api = { msg, prePage, request, uploadImg, doRequest, logout, isVip, setUserInfo, defConfig, globalData, getPlace, changeLocation }; //#ifdef H5 Vue.prototype.$jweixin = jweixin; //#endif App.mpType = 'app' const app = new Vue({ ...App }) app.$mount()