feat: 设置关联应用

This commit is contained in:
wangdan-fit2cloud 2023-12-04 18:28:42 +08:00
parent ed925c5838
commit 511d8fc6f2
5 changed files with 49 additions and 43 deletions

View File

@ -20,6 +20,7 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { computed } from 'vue' import { computed } from 'vue'
defineOptions({ name: 'CardCheckbox' })
const props = defineProps<{ const props = defineProps<{
data: any data: any

View File

@ -14,6 +14,8 @@ import TagEllipsis from './tag-ellipsis/index.vue'
import CommonList from './common-list/index.vue' import CommonList from './common-list/index.vue'
import MarkdownRenderer from './markdown-renderer/index.vue' import MarkdownRenderer from './markdown-renderer/index.vue'
import dynamicsForm from './dynamics-form' import dynamicsForm from './dynamics-form'
import CardCheckbox from './card-checkbox/index.vue'
export default { export default {
install(app: App) { install(app: App) {
app.component(AppIcon.name, AppIcon) app.component(AppIcon.name, AppIcon)
@ -31,5 +33,6 @@ export default {
app.component(CommonList.name, CommonList) app.component(CommonList.name, CommonList)
app.use(dynamicsForm) app.use(dynamicsForm)
app.component(MarkdownRenderer.name, MarkdownRenderer) app.component(MarkdownRenderer.name, MarkdownRenderer)
app.component(CardCheckbox.name, CardCheckbox)
} }
} }

View File

@ -27,7 +27,6 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, watch } from 'vue' import { ref, watch } from 'vue'
import CardCheckbox from '@/components/card-checkbox/index.vue'
const props = defineProps({ const props = defineProps({
data: { data: {
type: Array<any>, type: Array<any>,

View File

@ -25,52 +25,24 @@
:autosize="{ minRows: 3 }" :autosize="{ minRows: 3 }"
/> />
</el-form-item> </el-form-item>
<el-form-item v-loading="loading">
<template #label
><h4 class="title-decoration-1 mb-16" style="color: var(--app-text-color)">
关联应用
</h4></template
>
<el-row justify="space-between" style="width: 100%">
<el-col :span="11" v-for="(item, index) in application_list" :key="index" class="mb-16">
<CardCheckbox value-field="id" :data="item" v-model="form.application_id_list">
<template #icon>
<AppAvatar
v-if="item.name"
:name="item.name"
pinyinColor
class="mr-12"
shape="square"
:size="32"
/>
</template>
{{ item.name }}
</CardCheckbox>
</el-col>
</el-row>
</el-form-item>
</el-form> </el-form>
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref, reactive, onMounted, onUnmounted, computed, watch } from 'vue' import { ref, reactive, onMounted, onUnmounted, computed, watch } from 'vue'
import useStore from '@/stores' import useStore from '@/stores'
import DatasetApi from '@/api/dataset'
import CardCheckbox from '@/components/card-checkbox/index.vue'
import type { ApplicationFormType } from '@/api/type/application'
const props = defineProps({ const props = defineProps({
data: { data: {
type: Object, type: Object,
default: () => {} default: () => {}
} }
}) })
const loading = ref<boolean>(false)
const { dataset } = useStore() const { dataset } = useStore()
const baseInfo = computed(() => dataset.baseInfo) const baseInfo = computed(() => dataset.baseInfo)
const application_list = ref<Array<ApplicationFormType>>([])
const form = ref<any>({ const form = ref<any>({
name: '', name: '',
desc: '', desc: '',
application_id_list: []
}) })
const rules = reactive({ const rules = reactive({
@ -85,10 +57,6 @@ watch(
if (value && JSON.stringify(value) !== '{}') { if (value && JSON.stringify(value) !== '{}') {
form.value.name = value.name form.value.name = value.name
form.value.desc = value.desc form.value.desc = value.desc
form.value.application_id_list = value.application_id_list
DatasetApi.listUsableApplication(value.id, loading).then((ok) => {
application_list.value = ok.data
})
} }
}, },
{ {

View File

@ -1,12 +1,35 @@
<template> <template>
<LayoutContainer header="设置"> <LayoutContainer header="设置">
<div class="dataset-setting"> <div class="dataset-setting main-calc-height">
<div class="p-24" v-loading="loading"> <el-scrollbar>
<BaseForm ref="BaseFormRef" :data="detail" /> <div class="p-24" v-loading="loading">
<div class="text-right"> <BaseForm ref="BaseFormRef" :data="detail" />
<el-button @click="submit" type="primary"> 保存 </el-button>
<h4 class="title-decoration-1 mb-16">关联应用</h4>
<el-row :gutter="12">
<el-col :span="12" v-for="(item, index) in application_list" :key="index" class="mb-16">
<CardCheckbox value-field="id" :data="item" v-model="application_id_list">
<template #icon>
<AppAvatar
v-if="item.name"
:name="item.name"
pinyinColor
class="mr-12"
shape="square"
:size="32"
/>
</template>
{{ item.name }}
</CardCheckbox>
</el-col>
</el-row>
<div class="text-right">
<el-button @click="submit" type="primary"> 保存 </el-button>
</div>
</div> </div>
</div> </el-scrollbar>
</div> </div>
</LayoutContainer> </LayoutContainer>
</template> </template>
@ -15,6 +38,7 @@ import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'
import BaseForm from '@/views/dataset/component/BaseForm.vue' import BaseForm from '@/views/dataset/component/BaseForm.vue'
import datasetApi from '@/api/dataset' import datasetApi from '@/api/dataset'
import type { ApplicationFormType } from '@/api/type/application'
import { MsgSuccess } from '@/utils/message' import { MsgSuccess } from '@/utils/message'
const route = useRoute() const route = useRoute()
const { const {
@ -25,11 +49,18 @@ const BaseFormRef = ref()
const loading = ref(false) const loading = ref(false)
const detail = ref({}) const detail = ref({})
const application_list = ref<Array<ApplicationFormType>>([])
const application_id_list = ref([])
async function submit() { async function submit() {
if (await BaseFormRef.value?.validate()) { if (await BaseFormRef.value?.validate()) {
loading.value = true loading.value = true
const obj = {
application_id_list: application_id_list.value,
...BaseFormRef.value.form
}
datasetApi datasetApi
.putDateset(id, BaseFormRef.value.form) .putDateset(id, obj)
.then((res) => { .then((res) => {
MsgSuccess('保存成功') MsgSuccess('保存成功')
loading.value = false loading.value = false
@ -46,7 +77,11 @@ function getDetail() {
.getDatesetDetail(id) .getDatesetDetail(id)
.then((res) => { .then((res) => {
detail.value = res.data detail.value = res.data
loading.value = false application_id_list.value = res.data?.application_id_list
datasetApi.listUsableApplication(id, loading).then((ok) => {
application_list.value = ok.data
loading.value = false
})
}) })
.catch(() => { .catch(() => {
loading.value = false loading.value = false