fix: 解决批量修改文件权限错误的问题 (#2799)

pull/2801/head
zhengkunwang 2023-11-03 18:51:43 +08:00 committed by GitHub
parent be46fc26df
commit 4b69d77d3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 39 additions and 14 deletions

View File

@ -1,6 +1,6 @@
<template>
<div>
<el-form ref="ruleForm" label-position="left" :model="form" label-width="100px">
<el-form ref="ruleForm" label-position="left" :model="form" label-width="100px" :rules="rules">
<el-form-item :label="$t('file.owner')">
<el-checkbox v-model="form.owner.r" :label="$t('file.rRole')" />
<el-checkbox v-model="form.owner.w" :label="$t('file.wRole')" />
@ -16,15 +16,16 @@
<el-checkbox v-model="form.public.w" :label="$t('file.wRole')" />
<el-checkbox v-model="form.public.x" :label="$t('file.xRole')" />
</el-form-item>
<el-form-item :label="$t('file.role')" required>
<el-form-item :label="$t('file.role')" required prop="mode">
<el-input v-model="form.mode" maxlength="4" @input="changeMode"></el-input>
</el-form-item>
</el-form>
</div>
</template>
<script setup lang="ts">
import { FormInstance } from 'element-plus';
import { computed, ref, toRefs, watch, onUpdated, onMounted } from 'vue';
import { FormInstance, FormRules } from 'element-plus';
import { computed, ref, toRefs, watch, onUpdated, onMounted, reactive } from 'vue';
import { Rules } from '@/global/form-rules';
interface Role {
r: boolean;
@ -46,6 +47,9 @@ const roles = ref<string[]>(['0', '1', '2', '3', '4', '5', '6', '7']);
const props = withDefaults(defineProps<Props>(), {
mode: '0755',
});
const rules = reactive<FormRules>({
mode: [Rules.requiredInput, Rules.filePermission],
});
const { mode } = toRefs(props);
const ruleForm = ref<FormInstance>();

View File

@ -461,6 +461,19 @@ const checkParamSimple = (rule: any, value: any, callback: any) => {
}
};
const checkFilePermission = (rule, value, callback) => {
if (value === '' || typeof value === 'undefined' || value == null) {
callback(new Error(i18n.global.t('commons.rule.filePermission')));
} else {
const regFilePermission = /^[0-7]{3,4}$/;
if (!regFilePermission.test(value)) {
callback(new Error(i18n.global.t('commons.rule.filePermission')));
} else {
callback();
}
}
};
interface CommonRule {
requiredInput: FormItemRule;
requiredSelect: FormItemRule;
@ -493,6 +506,7 @@ interface CommonRule {
disabledFunctions: FormItemRule;
leechExts: FormItemRule;
domainWithPort: FormItemRule;
filePermission: FormItemRule;
paramCommon: FormItemRule;
paramComplexity: FormItemRule;
@ -692,4 +706,9 @@ export const Rules: CommonRule = {
validator: checkDomainWithPort,
trigger: 'blur',
},
filePermission: {
required: true,
validator: checkFilePermission,
trigger: 'blur',
},
};

View File

@ -189,6 +189,7 @@ const message = {
disableFunction: 'Only support letters ,underscores,and,',
leechExts: 'Only support letters, numbers and,',
paramSimple: 'Support lowercase letters and numbers, length 1-128',
filePermission: 'File Permission Error',
},
res: {
paramError: 'The request failed, please try again later!',

View File

@ -188,6 +188,7 @@ const message = {
disableFunction: ',',
leechExts: ',',
paramSimple: ', 1-128',
filePermission: '',
},
res: {
paramError: ',!',

View File

@ -188,6 +188,7 @@ const message = {
disableFunction: '线,',
leechExts: ',',
paramSimple: ',1-128',
filePermission: '',
},
res: {
paramError: ',!',

View File

@ -5,16 +5,9 @@
</template>
<el-row>
<el-col :span="22" :offset="1">
<FileRole v-loading="loading" :mode="mode" @get-mode="getMode"></FileRole>
<el-form
ref="fileForm"
label-position="left"
:model="addForm"
label-width="100px"
:rules="rules"
v-loading="loading"
>
<el-col :span="22" :offset="1" v-loading="loading">
<FileRole :mode="mode" @get-mode="getMode"></FileRole>
<el-form ref="fileForm" label-position="left" :model="addForm" label-width="100px" :rules="rules">
<el-form-item :label="$t('commons.table.user')" prop="user">
<el-input v-model.trim="addForm.user" />
</el-form-item>
@ -76,6 +69,7 @@ const addForm = reactive({
});
const acceptParams = (props: BatchRoleProps) => {
addForm.paths = [];
files.value = props.files;
files.value.forEach((file) => {
addForm.paths.push(file.path);
@ -94,7 +88,12 @@ const getMode = (val: number) => {
};
const submit = async () => {
const regFilePermission = /^[0-7]{3,4}$/;
if (!regFilePermission.test(addForm.mode.toString(8))) {
return;
}
loading.value = true;
BatchChangeRole(addForm)
.then(() => {
MsgSuccess(i18n.global.t('commons.msg.updateSuccess'));