oak-general-business/es/components/application/cos/index.js

112 lines
3.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { cloneDeep, set } from 'oak-domain/lib/utils/lodash';
import { generateNewId } from 'oak-domain/lib/utils/uuid';
import { isEmptyJsonObject } from '../../../utils/strings';
export default OakComponent({
isList: false,
properties: {
config: {},
entity: 'application',
entityId: '',
name: '',
},
data: {
initialConfig: {},
dirty: false,
currentConfig: {},
selections: [],
},
lifetimes: {
async ready() {
const { config } = this.props;
this.setState({
initialConfig: config,
dirty: false,
currentConfig: cloneDeep(config),
});
const systemId = this.features.application.getApplication().systemId;
const { data: [system] } = await this.features.cache.refresh("system", {
data: {
config: {
Cos: {
qiniu: 1,
ctyun: 1,
aliyun: 1,
tencent: 1,
local: 1,
s3: 1,
},
},
},
filter: {
id: systemId,
}
});
const cosConfig = system?.config?.Cos;
// 如果key存在并且不为defaultOrigin并且value的keys长度大于0则加入选择项
const selections = [];
if (cosConfig) {
for (const [key, value] of Object.entries(cosConfig)) {
if (key === 'defaultOrigin') {
continue;
}
if (value && !isEmptyJsonObject(value)) {
selections.push({
name: key,
value: key,
});
}
}
}
this.setState({
selections,
});
}
},
methods: {
setValue(path, value) {
const { currentConfig } = this.state;
const newConfig = cloneDeep(currentConfig || {});
set(newConfig, path, value);
this.setState({
currentConfig: newConfig,
dirty: true,
});
},
resetConfig() {
const { initialConfig } = this.state;
this.setState({
dirty: false,
currentConfig: cloneDeep(initialConfig),
});
},
async updateConfig() {
const { currentConfig } = this.state;
const { entity, entityId } = this.props;
if (!entityId) {
this.setMessage({
content: '缺少实体ID无法更新配置',
type: 'error',
});
return;
}
await this.features.cache.operate("application", {
id: generateNewId(),
action: 'update',
data: {
config: currentConfig,
},
filter: {
id: entityId,
}
}, {});
this.setMessage({
content: '操作成功',
type: 'success',
});
this.setState({
dirty: false,
});
},
},
});