代码拉取完成,页面将自动刷新
import Vue from 'vue'
import store from './store'
import App from './App'
import * as filters from './filters'
import * as config from './config'
//自定义modal
import initModal from "@/components/zhangxu-showModal/initModal.js";
import showModal from '@/components/zhangxu-showModal/show-modal';
initModal(Vue);
Vue.component('show-modal',showModal);
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 = 1500, 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)
}
if (!loginLock) {
loginLock = true
uni.showModal({
title: '登录提示',
content: '您尚未登录,是否立即登录?',
showCancel: true,
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 = (num = 9,successCallback) => {
let baseUrl = config.def().baseUrl
uni.chooseImage({
sizeType: ['compressed'],
count:num,
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 = {}
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
//zj 2.17 统一获取地理信息
//isChoose 是否 chooseLocation 接口返回的经纬度 该接口返回的address没做省市区划分
Vue.prototype.$getLocation = async (isChoose=false,latitude='',longitude='')=>{
var ret = {}
if(isChoose){
ret.latitude = res.latitude
ret.longitude = res.longitude
}else{
var [err,res] = await uni.getLocation({
type: 'wgs84'
})
if(res.errMsg === 'getLocation:ok'){
ret.latitude = res.latitude
ret.longitude = res.longitude
}else{
return false
}
}
var [error,geocodeData] = await uni.request({
url:"https://restapi.amap.com/v3/geocode/regeo",
method:"GET",
data:{
key:'49ddbf4ad01c98ad1d5a63a23ddd4959',
location:ret.longitude+','+ret.latitude,
extensions:'all',
// poitype:'120000|060000'返回poi限定范围
}
})
if(geocodeData.statusCode === 200){
console.log(geocodeData)
var data = geocodeData.data.regeocode.addressComponent
for(var key in data){
ret[key] = data[key]
}
ret.pois = geocodeData.data.regeocode.pois
return ret
}else{
return false
}
}
App.mpType = 'app'
const app = new Vue({
...App
})
app.$mount()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。