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.
|
|
|
import { model, Model } from '@core/core';
|
|
|
|
|
|
|
|
type RootInfo = {
|
|
|
|
url: string; // api url
|
|
|
|
prefix: string; // 路径前缀
|
|
|
|
root: string; // 根文件夹名称
|
|
|
|
};
|
|
|
|
|
|
|
|
export const ROOT_INFO_MAP: Record<string, RootInfo> = {
|
|
|
|
// 证书 resources/certificates/
|
|
|
|
certificates: {
|
|
|
|
url: '/v10/certificates/all',
|
|
|
|
prefix: 'resources/',
|
|
|
|
root: 'certificates',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
@model()
|
|
|
|
export class FileChooserModel extends Model {
|
|
|
|
static xtype = 'dec.dcm.model.components.file_chooser';
|
|
|
|
|
|
|
|
private options: {
|
|
|
|
root: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
state() {
|
|
|
|
return {
|
|
|
|
keyword: '', // 搜索关键字
|
|
|
|
items: [], // 文件项
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
actions = {
|
|
|
|
/**
|
|
|
|
* 请求获取items
|
|
|
|
* @param callback 回调
|
|
|
|
*/
|
|
|
|
requestGetItems: (callback?: Function) => {
|
|
|
|
const { keyword } = this.model;
|
|
|
|
const { url, prefix, root } = ROOT_INFO_MAP[this.options.root];
|
|
|
|
const requestUrl = `${url}?keyword=${encodeURIComponent(keyword)}`;
|
|
|
|
Dec.reqGetHandle(requestUrl, '', (data) => {
|
|
|
|
this.model.items = data
|
|
|
|
.concat({
|
|
|
|
id: root,
|
|
|
|
text: prefix + root,
|
|
|
|
value: prefix + root,
|
|
|
|
isParent: true,
|
|
|
|
})
|
|
|
|
.map((item) => ({
|
|
|
|
...item,
|
|
|
|
value: prefix + item.path,
|
|
|
|
open: item.id === root || BI.isKey(keyword),
|
|
|
|
}));
|
|
|
|
BI.isFunction(callback) && callback();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 设置keyword
|
|
|
|
* @param value
|
|
|
|
*/
|
|
|
|
setKeyword: (value: string) => {
|
|
|
|
this.model.keyword = value;
|
|
|
|
this.requestGetItems();
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|