12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- //处理头像名称
- export const getUserName = (name) => {
- const leng = name.length;
- const pattern = new RegExp(/[0-9a-z]/i);
- if (pattern.test(name)) {
- return name.substr(leng - 3, 3)
- } else {
- return name.substr(leng - 2, 2)
- }
- }
- //选择图片文件
- export const chooseImage = (count) => {
- return new Promise((resolve) => {
- uni.chooseImage({
- count: count,
- sizeType: ['original'],
- sourceType: ['album', 'camera'],
- success: ({tempFiles}) => {
- resolve(tempFiles);
- },
- fail: () => {
- resolve([]);
- }
- });
- })
- }
- //选择视频文件
- export const chooseVideo = () => {
- return new Promise((resolve) => {
- uni.chooseVideo({
- sourceType: ['camera', 'album'],
- success: (res) => {
- resolve(res);
- },
- fail: () => {
- resolve({});
- }
- });
- })
- }
- export const filterSize = (size) => {
- if (!size) return '';
- if (size < pow1024(1)) return size + ' B';
- if (size < pow1024(2)) return (size / pow1024(1)).toFixed(2) + ' KB';
- if (size < pow1024(3)) return (size / pow1024(2)).toFixed(2) + ' MB';
- if (size < pow1024(4)) return (size / pow1024(3)).toFixed(2) + ' GB';
- return (size / pow1024(4)).toFixed(2) + ' TB'
- }
- // 求次幂
- function pow1024(num) {
- return Math.pow(1024, num)
- }
|