Skip to content

Commit

Permalink
feat: 文件型配置支持文件内容编码选择--story=120473383 (#78)
Browse files Browse the repository at this point in the history
* feat: 新增配置文件支持编码选择

* feat: 批量导入支持设置编码

* fix: 解决合并冲突
  • Loading branch information
Yuikill authored Nov 26, 2024
1 parent d077b17 commit 1271121
Show file tree
Hide file tree
Showing 13 changed files with 389 additions and 230 deletions.
2 changes: 2 additions & 0 deletions ui/src/i18n/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ export default {
字段说明: 'Field description',
格式说明: 'Format description',
'示例:': 'Example:',
编码: 'Encoding',
批量设置编码: 'Batch set encoding',
查看服务属性: 'View service attributes',
'在未命名版本中发现过期证书,请处理证书问题后再生成版本': 'Expired certificates found in the unnamed version. Please handle the certificate issue before generating the version',
'30天内过期的证书列表': 'List of certificates expiring within 30 days',
Expand Down
2 changes: 2 additions & 0 deletions ui/src/i18n/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,8 @@ export default {
字段说明: '字段说明',
格式说明: '格式说明',
'示例:': '示例:',
编码: '编码',
批量设置编码: '批量设置编码',
查看服务属性: '查看服务属性',
'在未命名版本中发现过期证书,请处理证书问题后再生成版本': '在未命名版本中发现过期证书,请处理证书问题后再生成版本',
'30天内过期的证书列表': '30天内过期的证书列表',
Expand Down
1 change: 1 addition & 0 deletions ui/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export function getConfigEditParams() {
user: 'root',
user_group: 'root',
privilege: '644',
charset: 'UTF-8',
revision_name: `v${dayjs().format('YYYYMMDDHHmmss')}`,
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@
</template>
</div>
<div class="btns">
<bk-select
v-if="charset"
class="charset-select"
v-model="currentCharset"
auto-focus
:filterable="false"
:clearable="false"
@change="emits('update:charset', currentCharset)">
<bk-option v-for="item in charsetList" :id="item" :key="item" :name="item" />
</bk-select>
<ReadFileContent
v-if="editable"
v-bk-tooltips="{
Expand Down Expand Up @@ -61,6 +71,7 @@
defineProps<{
content: string;
editable: boolean;
charset?: string;
variables?: IVariableEditParams[];
sizeLimit?: number;
language?: string;
Expand All @@ -77,10 +88,12 @@
},
);
const emits = defineEmits(['change']);
const emits = defineEmits(['change', 'update:charset']);
const isOpenFullScreen = ref(false);
const codeEditorRef = ref();
const charsetList = ['UTF-8', 'GBK'];
const currentCharset = ref(props.charset);
const editorStyle = computed(() => {
return {
Expand Down Expand Up @@ -160,4 +173,17 @@
height: calc(100% - 40px);
}
}
.charset-select {
:deep(.bk-input) {
width: 80px;
height: 26px;
background: #2e2e2e;
border: 1px solid #4d4f56;
border-radius: 2px;
.bk-input--text {
background: #2e2e2e;
color: #979ba5;
}
}
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
</div>
</template>
<ConfigContentEditor
v-model:charset="localVal.charset"
:content="stringContent"
:editable="true"
:variables="props.variables"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@
item.user = 'root';
item.user_group = 'root';
item.file_name = option.file.name;
item.charset = 'UTF-8';
});
res.exist.forEach((item: IConfigImportItem) => {
item.file_name = option.file.name;
item.charset = item.charset || 'UTF-8';
});
emits('change', res.exist, res.non_exist);
} catch (e: any) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,16 @@
byte_size = detail.content.byte_size;
signature = detail.content.signature;
}
const { name, memo, path, file_type, permission } = detail.config_item.spec;
configForm.value = { id: props.configId, name, memo, file_type, path, ...permission };
const { name, memo, path, file_type, permission, charset } = detail.config_item.spec;
configForm.value = {
id: props.configId,
name,
memo,
file_type,
path,
charset: charset || 'UTF-8',
...permission,
};
if (file_type === 'binary') {
content.value = { name, signature, size: byte_size };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
user: string;
user_group: string;
privilege: string;
charset?: string;
}
const { versionData } = storeToRefs(useConfigStore());
Expand Down Expand Up @@ -151,6 +152,7 @@
user: '',
user_group: '',
privilege: '',
charset: '',
});
const content = ref<string | IFileConfigContentSummary>('');
const variables = ref<IVariableEditParams[]>([]);
Expand Down Expand Up @@ -203,7 +205,7 @@
const { content, memo } = res.config_item.commit_spec;
const { byte_size, origin_byte_size, signature, origin_signature, md5 } = content;
const { create_at, creator, update_at, reviser } = res.config_item.revision;
const { name, path, file_type, file_mode, permission } = res.config_item.spec;
const { name, path, file_type, file_mode, permission, charset } = res.config_item.spec;
const { user, user_group, privilege } = permission;
configDetail.value = sortObjectKeysByAscii({
name,
Expand All @@ -223,11 +225,12 @@
user,
user_group,
privilege,
charset,
});
} else {
const res = await getConfigItemDetail(props.bkBizId, props.id, props.appId);
const { create_at, creator, update_at, reviser } = res.config_item.revision;
const { name, memo, path, file_type, file_mode, permission } = res.config_item.spec;
const { name, memo, path, file_type, file_mode, permission, charset } = res.config_item.spec;
const { user, user_group, privilege } = permission;
const { byte_size, signature, md5 } = res.content;
configDetail.value = sortObjectKeysByAscii({
Expand All @@ -246,6 +249,7 @@
user,
user_group,
privilege,
charset,
});
}
const signature = versionData.value.id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
<template>
<bk-popover ext-cls="popover-wrap" theme="light" trigger="manual" placement="bottom" :is-show="isShow">
<edit-line class="edit-line" @click="isShow = true" />
<template #content>
<div
:class="['pop-wrap', { 'privilege-wrap': setType === 'privilege' }]"
v-click-outside="() => (isShow = false)">
<div class="pop-content">
<div class="pop-title">{{ title }}</div>
<template v-if="setType === 'privilege'">
<bk-input
v-model="localVal"
style="width: 184px; margin-bottom: 16px"
@blur="testPrivilegeInput"></bk-input>
<span class="error-tip" style="margin-left: 10px" v-if="isShowPrivilegeError">
{{ t('只能输入三位 0~7 数字且文件own必须有读取权限') }}
</span>
<div class="privilege-select-panel">
<div v-for="(item, index) in PRIVILEGE_GROUPS" class="group-item" :key="index" :label="item">
<div class="header">{{ item }}</div>
<div class="checkbox-area">
<bk-checkbox-group
class="group-checkboxs"
:model-value="privilegeGroupsValue(localVal)[index]"
@change="handleSelectPrivilege(index, $event)">
<bk-checkbox size="small" :label="4" :disabled="index === 0">{{ t('') }}</bk-checkbox>
<bk-checkbox size="small" :label="2">{{ t('') }}</bk-checkbox>
<bk-checkbox size="small" :label="1">{{ t('执行') }}</bk-checkbox>
</bk-checkbox-group>
</div>
</div>
</div>
</template>
<bk-select
v-else-if="setType === 'charset'"
class="charset-select"
v-model="localVal"
auto-focus
:filterable="false"
:clearable="false">
<bk-option v-for="charset in charsetList" :id="charset" :key="charset" :name="charset" />
</bk-select>
<bk-input v-else v-model="localVal"></bk-input>
</div>
<div class="pop-footer">
<div class="button">
<bk-button theme="primary" style="margin-right: 8px; width: 80px" size="small" @click="handleConfirm">
{{ $t('确定') }}
</bk-button>
<bk-button size="small" @click="handleCancel">{{ $t('取消') }}</bk-button>
</div>
</div>
</div>
</template>
</bk-popover>
</template>

<script lang="ts" setup>
import { ref, computed } from 'vue';
import { EditLine } from 'bkui-vue/lib/icon';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const props = defineProps<{
title: string;
setType?: string;
}>();
const emits = defineEmits(['update:isShow', 'confirm']);
const PRIVILEGE_GROUPS = [t('属主(own)'), t('属组(group)'), t('其他人(other)')];
const PRIVILEGE_VALUE_MAP = {
0: [],
1: [1],
2: [2],
3: [1, 2],
4: [4],
5: [1, 4],
6: [2, 4],
7: [1, 2, 4],
};
const charsetList = ['UTF-8', 'GBK'];
const isShow = ref(false);
const localVal = ref(props.setType === 'privilege' ? '644' : '');
const isShowPrivilegeError = ref(false);
const testPrivilegeInput = () => {
const val = String(localVal.value);
const own = parseInt(localVal.value[0], 10);
if (/^[0-7]{3}$/.test(val) && own >= 4) {
isShowPrivilegeError.value = false;
} else {
localVal.value = '644';
isShowPrivilegeError.value = true;
}
};
// 将权限数字拆分成三个分组配置
const privilegeGroupsValue = computed(() => (privilege: string) => {
const data: { [index: string]: number[] } = { 0: [], 1: [], 2: [] };
if (privilege.length > 0) {
const valArr = privilege.split('').map((i) => parseInt(i, 10));
valArr.forEach((item, index) => {
data[index as keyof typeof data] = PRIVILEGE_VALUE_MAP[item as keyof typeof PRIVILEGE_VALUE_MAP];
});
}
return data;
});
// 选择文件权限
const handleSelectPrivilege = (index: number, val: number[]) => {
const groupsValue = { ...privilegeGroupsValue.value(localVal.value) };
groupsValue[index] = val;
const digits = [];
for (let i = 0; i < 3; i++) {
let sum = 0;
if (groupsValue[i].length > 0) {
sum = groupsValue[i].reduce((acc, crt) => acc + crt, 0);
}
digits.push(sum);
}
const newVal = digits.join('');
localVal.value = newVal;
isShowPrivilegeError.value = false;
};
const handleConfirm = () => {
if (props.setType === 'privilege' && isShowPrivilegeError.value) {
return;
}
emits('confirm', localVal.value);
isShow.value = false;
};
const handleCancel = () => {
localVal.value = '';
isShow.value = false;
};
</script>

<style scoped lang="scss">
.edit-line {
color: #3a84ff;
cursor: pointer;
text-align: right;
}
.pop-wrap {
width: 240px;
.pop-content {
padding: 16px;
.pop-title {
line-height: 24px;
font-size: 16px;
padding-bottom: 10px;
}
.bk-input,.charset-select {
width: 150px;
}
}
.pop-footer {
position: relative;
height: 42px;
background: #fafbfd;
border-top: 1px solid #dcdee5;
.button {
position: absolute;
right: 16px;
top: 50%;
transform: translateY(-50%);
}
}
}
.privilege-select-panel {
display: flex;
align-items: top;
border: 1px solid #dcdee5;
.group-item {
.header {
padding: 0 16px;
height: 42px;
line-height: 42px;
color: #313238;
font-size: 12px;
background: #fafbfd;
border-bottom: 1px solid #dcdee5;
}
&:not(:last-of-type) {
.header,
.checkbox-area {
border-right: 1px solid #dcdee5;
}
}
}
.checkbox-area {
padding: 10px 16px 12px;
background: #ffffff;
&:not(:last-child) {
border-right: 1px solid #dcdee5;
}
}
.group-checkboxs {
font-size: 12px;
.bk-checkbox ~ .bk-checkbox {
margin-left: 16px;
}
:deep(.bk-checkbox-label) {
font-size: 12px;
}
}
}
.error-tip {
color: red;
}
.privilege-wrap {
width: auto;
}
</style>
Loading

0 comments on commit 1271121

Please sign in to comment.