intelligentGroup/tools/tools.js

100 lines
2.4 KiB
JavaScript
Raw Normal View History

2023-09-08 14:52:40 +08:00
import $store from '@/store'
export default {
msg,
getCall,
getTime,
getDate,
NewsPtype,
GetDateStr,
}
function NewsPtype(con) {
//1小程序2H5,3内练4文本
if (con.ptype == 1) {
uni.navigateToMiniProgram({
appId: con.appid,
path: con.content,
extraData: {},
})
return
}
if (con.ptype == 3) {
uni.navigateTo({
url: con.content
})
return
}
if (con.ptype == 4 || con.ptype == 2) {
uni.navigateTo({
url: "/pageTwo/news/detail?id=" + con.id + "&type=" + con.type
})
return
}
}
function getCall(authlist, num) {
2023-09-15 14:26:04 +08:00
console.log("authlist", authlist)
if (authlist.length) {
let arr = authlist.findIndex(v => v.code == 'phone:show')
if (arr == -1) {
$store.commit("changeSecratary", true);
} else {
uni.makePhoneCall({
phoneNumber: num //仅为示例
}).catch((e) => {
console.log(e) //用catch(e)来捕获错误{makePhoneCall:fail cancel}
});
}
2023-09-08 14:52:40 +08:00
} else {
2023-09-15 14:26:04 +08:00
$store.commit("changeSecratary", true);
2023-09-08 14:52:40 +08:00
}
}
function msg(str) {
uni.showToast({
title: str,
duration: 3000,
icon: 'none'
})
}
function getDate(type) {
const date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
month = month > 9 ? month : '0' + month;;
day = day > 9 ? day : '0' + day;
if (type === 'start') {
year = year;
return `${year}-${month}-${day}`;
}
if (type === 'end') {
year = year + 7;
return `${year}-${month}-${day}`;
}
if (type === 'month') {
return month + '月' + day + '日'
}
}
function GetDateStr(AddDayCount) {
var dd = new Date();
dd.setDate(dd.getDate() + AddDayCount); //获取AddDayCount天后的日期
var y = dd.getFullYear();
var m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd.getMonth() + 1); //获取当前月份的日期不足10补0
var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate(); //获取当前几号不足10补0
return y + "-" + m + "-" + d;
}
function getTime() {
var date = new Date()
var y = date.getFullYear();
var m = (date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1) : (date.getMonth() +
1); //获取当前月份的日期不足10补0
var d = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
let H = date.getHours() > 9 ? date.getHours() : '0' + date.getHours()
let Min = date.getMinutes() > 9 ? date.getMinutes() : '0' + date.getMinutes()
return y + '/' + m + '/' + d + " " + H + ':' + Min
}