websoft-uniapp仓库模板
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.
 
 
 
 
 
 

211 lines
5.1 KiB

import { listDictionaryData } from '@/uni_modules/ws-common/api/system/dictionary-data';
import { ref } from 'vue';
import { pageProject } from '@/api/oa/project';
// import { getJson } from '@/api/json';
import { APP_SECRET, FILE_SERVER } from '@/config/setting';
import { useUserStore } from '@/store/modules/user';
import CryptoJS from 'crypto-js';
// 生成编号
export function createCode() : string {
const data = new Date();
const code = `${data.getFullYear()}${data.getMonth()}${data.getDate()}${data.getHours()}${data.getMilliseconds()}`;
return code.slice(0);
}
// 生成商户编号
export function createMerchantCode() : string {
const data = new Date();
const code = `${data.getFullYear()}${data.getMonth()}${data.getDate()}${data.getSeconds()}`;
return code.slice(3);
}
// 生成订单编号
export function createOrderNo() : string {
const data = new Date();
const code = `${data.getFullYear()}${data.getMonth()}${data.getDate()}${data.getHours()}${data.getMilliseconds()}${random(
8000,
12000
)}`;
return code.slice(0);
}
/**
* @description 取一个区间数
* @param {Number} min 最小值
* @param {Number} max 最大值
*/
export function random(min : number, max : number) {
if (min >= 0 && max > 0 && max >= min) {
const gab = max - min + 1
return Math.floor(Math.random() * gab + min)
}
return 0
}
// 跳转页面(不弹窗)
export function navTo(url : string) : void {
window.location.href = url;
}
// 手机号脱敏
export function getMobile(tel : string) {
const reg = /^(\d{3})\d{4}(\d{4})$/;
return tel.replace(reg, '$1****$2');
}
// 复制文本
export const copyText = (text : string) => {
// 模拟 输入框
const cInput = document.createElement('input');
cInput.value = text;
document.body.appendChild(cInput);
cInput.select(); // 选取文本框内容
// 执行浏览器复制命令
// 复制命令会将当前选中的内容复制到剪切板中(这里就是创建的input标签)
// Input要在正常的编辑状态下原生复制方法才会生效
document.execCommand('copy');
// 复制成功后再将构造的标签 移除
document.body.removeChild(cInput);
};
/**
* 获取字典数据作为下拉选项数据
* @param dictCode
*/
// export const getDictionaryOptions = (dictCode : any) => {
// const dictOptions = ref<any>([]);
// // const storageData = localStorage.getItem('__' + dictCode + '__');
// listDictionaryData({
// dictCode
// })
// .then((list) => {
// // 获取远程字典数据
// if (list.length > 0) {
// dictOptions.value = list.map((d) => {
// return {
// value: d.dictDataCode,
// label: d.dictDataName,
// text: d.dictDataName,
// comments: d.comments
// };
// });
// } else {
// // 未定义则取默认的json数据
// dictOptions.value = getJson(dictCode);
// }
// })
// .catch((e) => {
// // message.error(e.message);
// });
// return <any>dictOptions;
// };
// 下拉选择项目
export const selectProject = (text : any) => {
const data = ref<any>([]);
pageProject({ projectName: text }).then((result) => {
data.value = result?.list.map((d) => {
return {
value: d.projectId,
label: d.projectName,
text: d.projectName
};
});
});
return data;
};
// 判断是否为图片
/*
* @param: fileName - 文件名称
*/
export const isImage = (fileName : string) => {
// 后缀获取
let suffix = '';
try {
const flieArr = fileName.split('.');
suffix = flieArr[flieArr.length - 1];
} catch (err) {
suffix = '';
}
const imgList = ['png', 'jpg', 'jpeg', 'bmp', 'gif'];
return imgList.some((item) => {
return item == suffix;
});
};
export const getWeek = (text : string | number) => {
const week = [
'星期日',
'星期一',
'星期二',
'星期三',
'星期四',
'星期五',
'星期六'
];
return week[text];
};
/**
* 文件大小转换
* @param text
*/
export const getFileSize = (text : any) => {
if (text < 1024) {
return text + 'B';
} else if (text < 1024 * 1024) {
return (text / 1024).toFixed(1) + 'KB';
} else if (text < 1024 * 1024 * 1024) {
return (text / 1024 / 1024).toFixed(1) + 'M';
} else {
return (text / 1024 / 1024 / 1024).toFixed(1) + 'G';
}
};
/* 原图转缩列图 */
export const thumbnail = (url : string) => {
if (url.indexOf('/thumbnail') < 0) {
return url.replace(FILE_SERVER, FILE_SERVER + '/thumbnail');
}
return url;
};
/* 缩列转图原图 */
export const original = (url : string) => {
if (url.indexOf('/thumbnail') == 0) {
return url.replace('/thumbnail', '');
}
return url;
};
export const getCompanyInfo = () => {
const user = useUserStore();
if (user.info?.companyInfo) {
return user.info?.companyInfo;
}
return null;
};
export const getVersion = () => {
const companyInfo = getCompanyInfo();
if (companyInfo?.version) {
return companyInfo?.version;
}
return null;
};
// AES加密
export const encrypt = (text : any) => {
return CryptoJS.AES.encrypt(text, APP_SECRET).toString();
};
// AES解密
export const decrypt = (encrypt : any) => {
CryptoJS.AES.decrypt(encrypt, APP_SECRET);
const bytes = CryptoJS.AES.decrypt(encrypt, APP_SECRET);
return bytes.toString(CryptoJS.enc.Utf8);
};