From b4ee3d0dfcd36118f4c0dd4a7ae6df6589121d7b Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 30 Jan 2021 00:06:50 +0800 Subject: [PATCH] refactor: input render --- other/certd-ui/src/components/HelloWorld.vue | 60 -------------- .../src/components/component-render.vue | 32 ++++++++ other/certd-ui/src/components/index.js | 16 ++++ .../provider-selector}/provider-manager.vue | 82 +++++++++---------- .../provider-selector}/provider-selector.vue | 15 +++- other/certd-ui/src/main.js | 4 +- .../src/views/detail/components/cert-form.vue | 2 - .../src/views/detail/components/task-form.vue | 7 +- other/certd-ui/src/views/detail/index.vue | 1 + .../plugins/src/aliyun/deploy-to-cdn/index.js | 11 ++- packages/providers/src/dns-provider/aliyun.js | 2 - packages/providers/src/dns-provider/dnspod.js | 10 ++- 12 files changed, 122 insertions(+), 120 deletions(-) delete mode 100644 other/certd-ui/src/components/HelloWorld.vue create mode 100644 other/certd-ui/src/components/component-render.vue create mode 100644 other/certd-ui/src/components/index.js rename other/certd-ui/src/{views/detail/components => components/provider-selector}/provider-manager.vue (76%) rename other/certd-ui/src/{views/detail/components => components/provider-selector}/provider-selector.vue (87%) diff --git a/other/certd-ui/src/components/HelloWorld.vue b/other/certd-ui/src/components/HelloWorld.vue deleted file mode 100644 index 1ef3aa8a..00000000 --- a/other/certd-ui/src/components/HelloWorld.vue +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - diff --git a/other/certd-ui/src/components/component-render.vue b/other/certd-ui/src/components/component-render.vue new file mode 100644 index 00000000..71c08143 --- /dev/null +++ b/other/certd-ui/src/components/component-render.vue @@ -0,0 +1,32 @@ + diff --git a/other/certd-ui/src/components/index.js b/other/certd-ui/src/components/index.js new file mode 100644 index 00000000..aec6c17b --- /dev/null +++ b/other/certd-ui/src/components/index.js @@ -0,0 +1,16 @@ +import DContainer from './d-container' +import ComponentRender from './component-render' +import ProviderSelector from './provider-selector/provider-selector' + +const list = [ + DContainer, + ComponentRender, + ProviderSelector +] +export default { + install (app) { + for (const item of list) { + app.component(item.name, item) + } + } +} diff --git a/other/certd-ui/src/views/detail/components/provider-manager.vue b/other/certd-ui/src/components/provider-selector/provider-manager.vue similarity index 76% rename from other/certd-ui/src/views/detail/components/provider-manager.vue rename to other/certd-ui/src/components/provider-selector/provider-manager.vue index d43d4e6f..abf38294 100644 --- a/other/certd-ui/src/views/detail/components/provider-manager.vue +++ b/other/certd-ui/src/components/provider-selector/provider-manager.vue @@ -23,7 +23,9 @@ - 【{{item.key}}】 {{ item.name }} + + {{ item.name }} ({{item.type}}) + @@ -38,7 +40,7 @@ - + {{option.label}} @@ -47,19 +49,15 @@ @@ -75,42 +73,21 @@ import { ref, reactive, nextTick, watch } from 'vue' import { useForm } from '@ant-design-vue/use' import _ from 'lodash-es' import providerApi from '@/api/api.providers' -function useEdit (props, context, providerList, onSave) { +function useEdit (props, context, providerList, onEditSave) { const formData = reactive({ key: '', name: '', - type: '' + type: undefined }) - const rules = reactive({ + const rules = ref({ type: [{ + type: 'string', required: true, message: '请选择类型' }], - key: [{ - required: true, - message: '请输入key' - }, { - validator (rule, value) { - const providers = providerList.value - if (!providers || providers.length === 0) { - return Promise.resolve() - } - if (editIndex.value != null) { - return Promise.resolve() - } - const filter = providers.filter(item => item.key === value) - console.log('validate', filter) - if (filter.length === 0) { - return Promise.resolve() - } else { - // eslint-disable-next-line prefer-promise-reject-errors - return Promise.reject('key不能重复') - } - }, - message: 'key不能与其他授权配置重复' - }], name: [{ + type: 'string', required: true, message: '请输入名称' }] @@ -121,9 +98,10 @@ function useEdit (props, context, providerList, onSave) { // const { resetFields, validate, validateInfos } = useForm(formData, rules) const onSubmit = async e => { e.preventDefault() - await formRef.value.validate() + const res = await formRef.value.validate() + console.log('validation:', res) const newProvider = _.cloneDeep(formData) - onSave(newProvider, editIndex.value) + onEditSave(newProvider, editIndex.value) closeEdit() } @@ -139,6 +117,7 @@ function useEdit (props, context, providerList, onSave) { changeType(item.type) } else { editIndex.value = null + formData.type = null } editVisible.value = true } @@ -192,6 +171,23 @@ function useEdit (props, context, providerList, onSave) { add } } + +let index = 0 +const keyPrefix = 'provider_' +function generateNewKey (list) { + index++ + let exists = false + for (const item of list) { + if (item.key === keyPrefix + index) { + exists = true + break + } + } + if (exists) { + return generateNewKey(list) + } + return keyPrefix + index +} export default { name: 'provider-manager', props: { @@ -219,11 +215,13 @@ export default { selectedKey.value = props.value }, { immediate: true }) - const onEditSave = (newProvier, editIndex) => { + const onEditSave = (newProvider, editIndex) => { if (editIndex == null) { - providerList.value.push(newProvier) + // add 生成一个key + newProvider.key = generateNewKey(providerList.value) + providerList.value.push(newProvider) } else { - _.merge(providerList.value[editIndex], newProvier) + _.merge(providerList.value[editIndex], newProvider) } } diff --git a/other/certd-ui/src/views/detail/components/provider-selector.vue b/other/certd-ui/src/components/provider-selector/provider-selector.vue similarity index 87% rename from other/certd-ui/src/views/detail/components/provider-selector.vue rename to other/certd-ui/src/components/provider-selector/provider-selector.vue index 6ab6d0a9..90bed9fe 100644 --- a/other/certd-ui/src/views/detail/components/provider-selector.vue +++ b/other/certd-ui/src/components/provider-selector/provider-selector.vue @@ -4,7 +4,7 @@ :value="value" @update:value="valueUpdate" > - + {{ item.name }} @@ -35,7 +35,8 @@ export default { }, providers: { type: Object - } + }, + filter: {} }, setup (props, context) { const providerManagerRef = ref(null) @@ -52,11 +53,19 @@ export default { const valueUpdate = (val) => { context.emit('update:value', val) } + + const isDisabled = (item) => { + if (!props.filter) { + return false + } + return item.type === props.filter + } return { providersUpdate, valueUpdate, providerManagerOpen, - providerManagerRef + providerManagerRef, + isDisabled } } } diff --git a/other/certd-ui/src/main.js b/other/certd-ui/src/main.js index a4dbd5e5..baad38ef 100644 --- a/other/certd-ui/src/main.js +++ b/other/certd-ui/src/main.js @@ -6,11 +6,11 @@ import 'ant-design-vue/dist/antd.css' import '@/style/common.less' import { i18n } from '@/i18n' import icons from './icons' -import DContainer from '@/components/d-container' +import components from './components' const app = createApp(App) app.config.productionTip = false app.use(i18n) app.use(Antd) icons(app) -app.component('d-container', DContainer) +app.use(components) app.use(router).mount('#app') diff --git a/other/certd-ui/src/views/detail/components/cert-form.vue b/other/certd-ui/src/views/detail/components/cert-form.vue index 329e620a..0c4f197d 100644 --- a/other/certd-ui/src/views/detail/components/cert-form.vue +++ b/other/certd-ui/src/views/detail/components/cert-form.vue @@ -71,7 +71,6 @@ import { reactive, toRaw, ref, watch } from 'vue' import { useForm } from '@ant-design-vue/use' import _ from 'lodash-es' -import ProviderSelector from '@/views/detail/components/provider-selector' function useDrawer () { const visible = ref(false) @@ -94,7 +93,6 @@ function useDrawer () { export default { name: 'cert-form', - components: { ProviderSelector }, emits: ['update:accessProviders', 'update:cert'], // 属性定义 props: { diff --git a/other/certd-ui/src/views/detail/components/task-form.vue b/other/certd-ui/src/views/detail/components/task-form.vue index d6bbb169..af2a0ecb 100644 --- a/other/certd-ui/src/views/detail/components/task-form.vue +++ b/other/certd-ui/src/views/detail/components/task-form.vue @@ -39,8 +39,8 @@ > - - + + @@ -57,12 +57,10 @@ -