88 :segmented =" {
99 content: true,
1010 action: true,
11- }" >
11+ }"
12+ >
1213 <n-card v-show =" !formData.type" >
1314 <n-grid x-gap =" 12" y-gap =" 12" :cols =" 2" >
1415 <n-gi v-for =" item in typeOptions" >
3334 />
3435 </n-form-item> -->
3536
36- <n-form-item :label =" t('Name')" >
37- <n-input v-model:value =" formData.name" :placeholder =" t('Please enter name')" />
37+ <n-form-item :label =" t('Name') + '(A-Z,0-9,_)' " >
38+ <n-input v-model:value =" formData.name" :allow-input = " onlyAllowLetter " : placeholder =" t('Please enter name')" />
3839 </n-form-item >
3940 <n-form-item :label =" t('Endpoint')" >
4041 <n-input v-model:value =" formData.endpoint" :placeholder =" t('Please enter endpoint')" />
5859 <n-input v-model:value =" formData.storageclass" :placeholder =" t('Please Enter storage class')" />
5960 </n-form-item >
6061 <n-space justify =" center" >
61- <n-button @click =" handleCancel" >{{ t(" Cancel" ) }}</n-button >
62- <n-button type =" primary" @click =" handleSave" >{{ t(" Save" ) }}</n-button >
62+ <n-button @click =" handleCancel" >{{ t(' Cancel' ) }}</n-button >
63+ <n-button type =" primary" @click =" handleSave" >{{ t(' Save' ) }}</n-button >
6364 </n-space >
6465 </n-form >
6566 </n-card >
6667 </n-modal >
6768</template >
6869
6970<script setup>
70- import { ref } from " vue" ;
71- import { useI18n } from " vue-i18n" ;
72- import MinioIcon from " ~/assets/svg/minio.svg" ;
73- import GoogleIcon from " ~/assets/svg/google.svg" ;
74- import AWSIcon from " ~/assets/svg/aws.svg" ;
75- import AzureIcon from " ~/assets/svg/azure.svg" ;
76- import AliyunIcon from " ~/assets/svg/aliyun.svg" ;
77- import TqyunIcon from " ~/assets/svg/tenxunyun.svg" ;
78- import HwcloudIcon from " ~/assets/svg/huaweiyun.svg" ;
79- import BaiduIcon from " ~/assets/svg/baiduyun.svg" ;
80- import RustfsIcon from " ~/assets/logo.svg" ;
81- import { NForm , NFormItem , NInput , NSelect , NButton } from " naive-ui" ;
82- import { useTiers } from " #imports" ;
71+ import { ref } from ' vue' ;
72+ import { useI18n } from ' vue-i18n' ;
73+ import MinioIcon from ' ~/assets/svg/minio.svg' ;
74+ import GoogleIcon from ' ~/assets/svg/google.svg' ;
75+ import AWSIcon from ' ~/assets/svg/aws.svg' ;
76+ import AzureIcon from ' ~/assets/svg/azure.svg' ;
77+ import AliyunIcon from ' ~/assets/svg/aliyun.svg' ;
78+ import TqyunIcon from ' ~/assets/svg/tenxunyun.svg' ;
79+ import HwcloudIcon from ' ~/assets/svg/huaweiyun.svg' ;
80+ import BaiduIcon from ' ~/assets/svg/baiduyun.svg' ;
81+ import RustfsIcon from ' ~/assets/logo.svg' ;
82+ import { NForm , NFormItem , NInput , NSelect , NButton } from ' naive-ui' ;
83+ import { useTiers } from ' #imports' ;
8384
8485const { t } = useI18n ();
8586const usetier = useTiers ();
8687const message = useMessage ();
8788
8889// 支持的存储类型
8990const typeOptions = [
90- { label: t (" RustFS" ), value: " rustfs" , iconUrl: RustfsIcon },
91- { label: t (" Minio" ), value: " minio" , iconUrl: MinioIcon },
92- { label: t (" AWS S3" ), value: " s3 " , iconUrl: AWSIcon },
91+ { label: t (' RustFS' ), value: ' rustfs' , iconUrl: RustfsIcon },
92+ { label: t (' Minio' ), value: ' minio' , iconUrl: MinioIcon },
93+ { label: t (' AWS S3' ), value: ' s3 ' , iconUrl: AWSIcon },
9394 // 暂未支持
9495 // { label: t('Google Cloud Storage'), value: 'google', iconUrl: GoogleIcon },
9596 // { label: t('Azure'), value: 'azure', iconUrl: AzureIcon },
@@ -101,21 +102,29 @@ const typeOptions = [
101102
102103const formRef = ref (null );
103104const formData = ref ({
104- type: " " ,
105- name: " " ,
106- endpoint: " " ,
107- accesskey: " " ,
108- secretkey: " " ,
109- bucket: " " ,
110- prefix: " " ,
111- region: " " ,
112- storageclass: " STANDARD" , // 新增字段,默认值为 STANDARD
105+ type: ' ' ,
106+ name: ' ' ,
107+ endpoint: ' ' ,
108+ accesskey: ' ' ,
109+ secretkey: ' ' ,
110+ bucket: ' ' ,
111+ prefix: ' ' ,
112+ region: ' ' ,
113+ storageclass: ' STANDARD' , // 新增字段,默认值为 STANDARD
113114});
114115
115116const rules = {
116- ruleName: { required: true , message: t (" Please enter rule name" ) },
117- type: { required: true , message: t (" Please select rule type" ) },
118- versionType: { required: true , message: t (" Please select version type" ) },
117+ name: { required: true , message: t (' Please enter rule name' ) },
118+ type: { required: true , message: t (' Please select rule type' ) },
119+ versionType: { required: true , message: t (' Please select version type' ) },
120+ };
121+
122+ // 只能是数字大写字母以及_组成,且不能以数字开头
123+ const onlyAllowLetter = value => {
124+ if (value === ' ' ) {
125+ return true ;
126+ }
127+ return / ^ [A-Z _][A-Z0-9 _] * $ / .test (value);
119128};
120129
121130const visible = ref (false );
@@ -128,9 +137,9 @@ defineExpose({
128137 open,
129138});
130139
131- const emmit = defineEmits ([" search" ]);
140+ const emmit = defineEmits ([' search' ]);
132141const handleSave = () => {
133- formRef .value ? .validate (( errors ) => {
142+ formRef .value ? .validate (errors => {
134143 if (! errors) {
135144 // {"type":"minio","minio":{"name":"COLDTIER","endpoint":"","bucket":"","prefix":"","region":"","accesskey":"","secretkey":""}}
136145 // 调用保存接口
@@ -149,12 +158,12 @@ const handleSave = () => {
149158 };
150159 usetier
151160 .addTiers (data)
152- .then (( res ) => {
161+ .then (res => {
153162 visible .value = false ;
154- emmit (" search" );
155- message .success (t (" Create Success" ));
163+ emmit (' search' );
164+ message .success (t (' Create Success' ));
156165 })
157- .catch (( err ) => {
166+ .catch (err => {
158167 message .error (err .message );
159168 });
160169 }
@@ -164,6 +173,6 @@ const handleSave = () => {
164173const handleCancel = () => {
165174 visible .value = false ;
166175 // 取消逻辑
167- formData .value .type = " " ;
176+ formData .value .type = ' ' ;
168177};
169178< / script>
0 commit comments