Commit d0a1655b authored by 吴永生#A02208's avatar 吴永生#A02208

feat: 文件传输开发

parent 644ad72e
/*
* @Author: 吴永生#A02208 yongsheng.wu@wholion.com
* @Date: 2022-06-13 16:50:40
* @LastEditors: 吴永生#A02208 yongsheng.wu@wholion.com
* @LastEditTime: 2022-06-13 21:09:24
* @FilePath: /bkunyun/src/hooks/useGlobalStore.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { useContext } from 'react';
import { MobXProviderContext } from 'mobx-react';
import { Stores } from '@/store';
export default function useGlobalStore<T extends keyof Stores>(storeName: T) {
const context = useContext(MobXProviderContext) as Stores;
return context[storeName];
}
\ No newline at end of file
/*
* @Author: 吴永生#A02208 yongsheng.wu@wholion.com
* @Date: 2022-06-13 17:00:19
* @LastEditors: 吴永生#A02208 yongsheng.wu@wholion.com
* @LastEditTime: 2022-06-14 11:06:13
* @FilePath: /bkunyun/src/store/modules/upload.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { makeAutoObservable } from "mobx";
interface IUploadInfo {
id: string,
open: boolean,
list: any,
isPermanence: boolean,
}
/** 存储地图派单websocket推送数据状态的store */
class FileList {
constructor() {
makeAutoObservable(this);
}
/** 文件上传列表 */
fileList: IUploadInfo[] = [];
setFileList (val: IUploadInfo[]) {
this.fileList = val
}
/** 设置文件上传信息 */
setUploadInfo(id: string, val: IUploadInfo) {
const newFileList = this.fileList?.map((item)=>{
if(item.id === id){
return val
} return item
})
this.fileList = newFileList
}
setUploadInfoOpen(id: string, val: boolean) {
const newFileList = this.fileList?.map((item)=>{
if(item.id === id){
return {...item,open: val};
}
return item;
})
this.fileList = newFileList
}
setUploadInfoList(id: string, val: any) {
const newFileList = this.fileList?.map((item)=>{
if(item.id === id){
return {...item, list: val}
} return item
})
this.fileList = newFileList
}
setUploadInfoIsPermanence(id: string, val: boolean) {
const newFileList = this.fileList?.map((item)=>{
if(item.id === id){
return {...item, isPermanence: val}
} return item
})
this.fileList = newFileList
}
}
export default new FileList();
This diff is collapsed.
/*
* @Author: 吴永生#A02208 yongsheng.wu@wholion.com
* @Date: 2022-06-13 17:23:49
* @LastEditors: 吴永生#A02208 yongsheng.wu@wholion.com
* @LastEditTime: 2022-06-13 17:28:59
* @FilePath: /bkunyun/src/utils/helper.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
const getTrueLength = (str: string) => {//获取字符串的真实长度(字节长度)
let len = str.length, truelen = 0;
for (let x = 0; x < len; x++) {
if (str.charCodeAt(x) > 128) {
truelen += 2;
} else {
truelen += 1;
}
}
return truelen;
}
export const verifyLettersNumbersCertainChars4 = (str: string) => {
if (str.slice(0, 1) === ".") {
return false;
}
if (getTrueLength(str) > 127) {
return false;
}
let validString = /^[\u4e00-\u9fa5_0-9a-zA-Z-_.]+$/;
return validString.test(str);
};
export const verifyLettersNumbersCertainChars5 = (str: string) => {
if (str.slice(0, 1) === ".") {
return false;
}
if (getTrueLength(str) > 127) {
return false;
}
let validString = /^[\u4e00-\u9fa5_0-9a-zA-Z\/-_.]+$/;
return validString.test(str);
};
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment