目录
三、经过我的一波疯狂骚操作,完成了前端的签名操作,顺利进入到了wx配置,那么接下来就开始wx api的走秀吧!!!!
一、用到的方法封装
(1)生成UUI
// 生成一个随机的UUID作为动态值
export const UUID = (len?: number, radix?: number) => {
const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
const uuid: any[] = [];
let i: any = 0;
radix = radix || chars.length;
if (len) {
for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
} else {
let r;
// 中间用特殊字符链接
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '';
uuid[14] = '4';
// 长度不长于32位
for (i = 0; i < 32; i++) {
if (!uuid[i]) {
r = 0 | (Math.random() * 16);
uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
}
}
}
return uuid.join('');
};
(2)生成时间戳或时间
const formatNumber = (n: any) => {
n = n.toString();
return n[1] ? n : `0${n}`;
};
export const formatTime = (date: { getFullYear: () => any; getMonth: () => number; getDate: () => any; getHours: () => any; getMinutes: () => any; getSeconds: () => any }, type: any) => {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
const hour = date.getHours();
const minute = date.getMinutes();
const second = date.getSeconds();
switch (type) {
case 'YY':
return `${[ye