mirror of
https://github.com/certd/certd.git
synced 2026-07-05 11:27:34 +08:00
chore(access-selector): add auto select first item function
1. 为access-selector组件添加defaultSelect属性支持自动选中第一个匹配项 2. 补全组件的typescript语法支持,新增onMounted等依赖导入 3. 在证书申请插件中启用默认选中功能
This commit is contained in:
@@ -16,8 +16,8 @@
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { defineComponent, reactive, ref, watch, inject } from "vue";
|
||||
<script lang="ts">
|
||||
import { defineComponent, reactive, ref, watch, inject, onMounted } from "vue";
|
||||
import CertAccessModal from "./access/index.vue";
|
||||
import { createAccessApi } from "../api";
|
||||
import { message } from "ant-design-vue";
|
||||
@@ -55,6 +55,10 @@ export default defineComponent({
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
defaultSelect: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
emits: ["update:modelValue", "change", "selectedChange"],
|
||||
setup(props, ctx) {
|
||||
@@ -158,12 +162,43 @@ export default defineComponent({
|
||||
},
|
||||
});
|
||||
|
||||
async function selectFirst(clearCurrent = false) {
|
||||
if (!clearCurrent && props.modelValue) {
|
||||
return;
|
||||
}
|
||||
const searchForm = projectStore.getSearchForm();
|
||||
const query: any = {
|
||||
query: {
|
||||
type: props.type,
|
||||
...searchForm,
|
||||
},
|
||||
page: { page: 1, pageSize: 1 },
|
||||
sort: { prop: "id", order: "ascending" },
|
||||
};
|
||||
if (props.subtype) {
|
||||
query.query.subtype = props.subtype;
|
||||
}
|
||||
const res = await api.GetList(query);
|
||||
const records = res?.records || [];
|
||||
if (records.length > 0) {
|
||||
await emitValue(records[0].id);
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
if (!props.defaultSelect) {
|
||||
return;
|
||||
}
|
||||
await selectFirst();
|
||||
});
|
||||
|
||||
return {
|
||||
clear,
|
||||
target,
|
||||
selectedId,
|
||||
providerDefine,
|
||||
chooseForm,
|
||||
selectFirst,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
@@ -375,6 +375,7 @@ export class CertApplyPlugin extends CertApplyBasePlugin {
|
||||
component: {
|
||||
name: "access-selector",
|
||||
type: "acmeAccount",
|
||||
defaultSelect: true,
|
||||
},
|
||||
required: false,
|
||||
helper: "直接本地生成,无需外部注册\n点击选择按钮->添加->填写邮箱->生成账号即可",
|
||||
|
||||
Reference in New Issue
Block a user