You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

144 lines
3.6 KiB

import vue from 'vue';
import qs from 'qs'
import app from '@/app'
// 过去本地文件
let getFile = function (config) {
return new Promise((ress, recs) => {
// uni.showActionSheet({
// itemList: uni.getStorageSync('language')=='zh-CN'?['拍照', '从相册中选择']:['Camera', 'Album'],
// success(res) {
// console.log(res.tapIndex,)
// let sourceType ='camera'
// if (res.tapIndex == 0) {
// sourceType = 'camera'
// } else if (res.tapIndex == 1) {
// sourceType = 'album'
// }
// uni.chooseImage({
// count: config.config || 9,
// sourceType: [sourceType],
// success: (chooseImageRes) => {
// ress(chooseImageRes)
// },
// fail: () => {
// recs()
// }
// });
// }
// })
uni.chooseImage({
count: config.config || 9,
success: (chooseImageRes) => {
ress(chooseImageRes)
},
fail: () => {
recc()
}
});
})
}
// 复制文本
function copy(txt) {
uni.setClipboardData({
data: txt,
success: function () {
uni.showToast({
title: uni.getStorageSync('language')=='zh-CN'?'复制成功':'success',
duration: 2000
});
}
});
}
// 页面后退方法
vue.prototype.$back = (num = 1) => {
uni.navigateBack({delta:num})
navFontColor()
}
// 标签过滤
function filterCode(str) {
return str.replace(/<[^<>]+>/g, '').replace(/&nbsp;/ig, '')
}
// 解决uni-app slot 数组传递bug
vue.prototype.$list = function (obj) {
return Object.entries(obj).filter(item => item[0] != '_i').map(item => item[1])
}
// 替换路由
vue.prototype._router = {
push(path) {
var url = '', query, animationType, animationDuration;
if (typeof path == 'string') {
url = path
} else {
url = path.path;
query = qs.stringify(path.query);
animationType = path.animationType
animationDuration = path.animationDuration
}
uni.navigateTo({
url: `${url}${url.includes('?') ? '&' : '?'}${query || ''}`,
animationType,
animationDuration
});
navFontColor()
},
replace(path) {
var url = '', query, animationType, animationDuration;
if (typeof path == 'string') {
url = path
} else {
url = path.path || '';
query = qs.stringify(path.query);
animationType = path.animationType
animationDuration = path.animationDuration
}
uni.redirectTo({
url: `${url}${url.includes('?') ? '&' : '?'}${query || ''}`,
animationType,
animationDuration
});
navFontColor()
}
}
function defaultTheme() {
return `dark`
// 获取当前时间
let timeNow = new Date();
// 获取当前小时
let hours = timeNow.getHours();
// 设置默认文字
let state = ``;
// 判断当前时间段
if (hours >= 19 || hours <= 7) {
state = `dark`;
} else {
state = `light`;
}
return state;
}
function navFontColor() {
let theme = uni.getStorageSync('theme') || defaultTheme()
setTimeout(() => {
uni.setNavigationBarColor({
frontColor: theme == 'light' ? '#000000' : '#ffffff',
backgroundColor: '#cccccc',
})
}, 300)
}
function localImgUrl(name) {
let theme = uni.getStorageSync('theme') || defaultTheme()
let str = theme == 'light' ? 'static/img/light/' : 'static/img/'
return str + name
}
vue.prototype.$imgUrl = app.imgUrl
vue.prototype.$baseUrl = app.baseUrl
vue.prototype.$getFile = getFile
vue.prototype.$copy = copy
vue.prototype.$filterCode = filterCode
vue.prototype.$navFontColor = navFontColor
vue.prototype.$localImgUrl = localImgUrl