integrated_traffic_uniapp/common/tool.js

188 lines
4.4 KiB
JavaScript
Raw Normal View History

2024-04-17 00:29:20 +08:00
2024-06-29 15:10:01 +08:00
// export var basePath = "http://192.168.0.62:7082/";
export var basePath = "http://192.168.0.103:6052/integrated_traffic/";
// export var basePath = "http://39.101.166.211:8073/integrated_traffic/";
2024-01-16 17:24:49 +08:00
export const baseImgPath = "https://file.zcloudchina.com/YTHFile";
export const adminPath = "http://192.168.0.18:8085";
export const projectManagerUrl = 'https://pm.qhdsafety.com/zy-projectManage/';
export const publicKey = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDUoHAavCikaZxjlDM6Km8cX+ye78F4oF39AcEfnE1p2Yn9pJ9WFxYZ4Vkh6F8SKMi7k4nYsKceqB1RwG996SvHQ5C3pM3nbXCP4K15ad6QhN4a7lzlbLhiJcyIKszvvK8ncUDw8mVQ0j/2mwxv05yH6LN9OKU6Hzm1ninpWeE+awIDAQAB'
//export const basePath = "http://192.168.0.9:8081";
export var corpinfoId = ''; //
export var loginUserId = '';
export var loginUser = '';
export function loginSession() {
2024-03-22 15:08:55 +08:00
if ('' == loginUserId || undefined == loginUserId ||
2024-01-16 17:24:49 +08:00
'' == loginUser || undefined == loginUser) {
uni.navigateTo({
url: '/pages/login/home',
});
}
}
export function setloginUser(user) {
loginUser = user;
}
export function setloginUserId(id) {
loginUserId = id
}
export function setCorpinfoId(id) {
corpinfoId = id
}
export var deptId = '';
export function setDeptId(id) {
deptId = id
}
export var deptLevel = '';
export function setDeptLevel(level) {
deptLevel = level
}
export var postId = '';
export function setPostId(id) {
postId = id
}
export var username = '';
export function setUsername(name) {
username = name
}
export var version = '';
export function setVersion(ver) {
version = ver
}
export function setBasePath(url) {
basePath = url
}
export var isRest = '';
export function setIsRest(rest) {
isRest = rest
}
export var premission = '';
export function setPremission(list) {
premission = list
}
export var updateInfo = false;
export function setUpdateInfo(flag) {
updateInfo = flag
}
export function formatDate(date, fmt) {
if (null != JSON.stringify(date) && 'null' != JSON.stringify(date) && undefined != JSON.stringify(date) && 'undefined' !=
JSON.stringify(date) && JSON.stringify(date) != '' && JSON.stringify(date).length > 0) {
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length))
}
let o = {
'M+': date.getMonth() + 1,
'd+': date.getDate(),
'h+': date.getHours(),
'm+': date.getMinutes(),
's+': date.getSeconds()
}
for (let k in o) {
if (new RegExp(`(${k})`).test(fmt)) {
let str = o[k] + ''
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str))
}
}
return fmt
} else {
return ''
}
}
function padLeftZero(str) {
return ('00' + str).substr(str.length)
}
// 处理多次点击
function noMultipleClicks(methods, e) {
let that = this;
if (that.noClick) {
that.noClick = false;
methods(e);
setTimeout(function() {
that.noClick = true;
}, 2000)
} else {
console.log("请稍后点击")
}
}
2024-03-22 15:08:55 +08:00
/**
* 验证身份证号码
*/
export function validateIdCard(value) {
return /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[0-2])(([0-2][1-9])|10|20|30|31)\d{3}(\d|X|x)$/.test(
value
)
}
/**
* 验证手机格式
*/
export function validateMobile(value) {
return /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-79])|(?:5[0-35-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[189]))\d{8}$/.test(value)
}
//获取数据字典数据
export async function getLevel(dataParams) {
const list = await sendPost(dataParams, '/dictionaries/getDictList')
return list
}
//获取数据字典数据3级字典
export async function getLevelCustom(dataParams) {
const list = await sendPost(dataParams, '/dictionaries/getLevelCustom')
return list
}
export async function listCorpAll(dataParams) {
const list = await sendPost(dataParams, '/app/corpinfo/listAll')
return list
}
/**
* 获取字典
*/
async function sendPost(dataParams, url) {
let resData = await uni.request({
method: 'POST',
dataType: 'json',
header: {
'Content-type': 'application/x-www-form-urlencoded'
},
url: basePath + url,
data: dataParams
})
return resData[1].data.list
}
export async function checkIdCard(dataParams) {
const data = await getData(dataParams, '/app/user/hasUserIdCard')
return data
}
/**
* 获取字典
*/
async function getData(dataParams, url) {
let resData = await uni.request({
method: 'POST',
dataType: 'json',
header: {
'Content-type': 'application/x-www-form-urlencoded'
},
url: basePath + url,
data: dataParams
})
return resData[1].data
}
2024-01-16 17:24:49 +08:00
//导出
export default {
noMultipleClicks, //禁止多次点击
}