¶Ô±ÈÐÂÎļþ |
| | |
| | | import { defineComponent, Fragment, ref } from 'vue' |
| | | import BaseDialog from '../BaseDialog/BaseDialog' |
| | | import { useVModel } from '@vueuse/core' |
| | | import styles from './ProjectConfig.module.scss' |
| | | import { getProjectConfig, createWidget } from '@/api/project-api' |
| | | import { menu, menuMap } from '@/config/menu' |
| | | import Icon from '../Icon/Icon' |
| | | import IconButton from '../IconButton/IconButton' |
| | | import DyForm from '../DyForm/DyForm' |
| | | import { ElLoading, ElMessage } from 'element-plus' |
| | | |
| | | export default defineComponent({ |
| | | name: 'project', |
| | | props: { |
| | | modelValue: { |
| | | type: Boolean, |
| | | default: false, |
| | | }, |
| | | }, |
| | | setup(props, { emit }) { |
| | | const visible = useVModel(props, 'modelValue', emit) |
| | | const baseVisible = ref(false) |
| | | const build = ref([]) |
| | | const local = ref([]) |
| | | const formData = ref({}) |
| | | const formRef = ref() |
| | | const openType = ref(1) |
| | | const onOpenDialog = async () => { |
| | | const buildProd = await getProjectConfig('.build.prod') |
| | | const localProd = await getProjectConfig('.build.local') |
| | | if (buildProd) { |
| | | try { |
| | | build.value = ( |
| | | (buildProd.data && buildProd.data.split('\n')) || |
| | | [] |
| | | ).filter((v) => v) |
| | | local.value = ( |
| | | (localProd.data && localProd.data.split('\n')) || |
| | | [] |
| | | ).filter((v) => v) |
| | | } catch (error) { |
| | | console.error(error) |
| | | } |
| | | } |
| | | } |
| | | const onConfirm = () => { |
| | | visible.value = false |
| | | } |
| | | const onClose = () => { |
| | | visible.value = false |
| | | } |
| | | const onAddWidget = (type: number) => { |
| | | baseVisible.value = true |
| | | openType.value = type |
| | | } |
| | | const onBaseConfirm = async () => { |
| | | await formRef.value.validate() |
| | | const loading = ElLoading.service({ |
| | | lock: true, |
| | | text: 'å建ä¸ï¼è¯·ç¨å...', |
| | | background: 'rgba(0, 0, 0, 0.7)', |
| | | }) |
| | | loading.close() |
| | | await createWidget({ |
| | | ...formData.value, |
| | | type: openType.value, |
| | | menu, |
| | | menuMap, |
| | | }) |
| | | |
| | | onBaseClose() |
| | | } |
| | | const onBaseClose = () => { |
| | | baseVisible.value = false |
| | | } |
| | | return () => { |
| | | return ( |
| | | <Fragment> |
| | | <BaseDialog |
| | | onOpen={onOpenDialog} |
| | | width="700px" |
| | | title="项ç®é
ç½®" |
| | | v-model={visible.value} |
| | | onConfirm={onConfirm} |
| | | onClose={onClose} |
| | | > |
| | | <div class={styles.projectConfig}> |
| | | <div class={styles.leftPane}> |
| | | <div class={styles.header}> |
| | | <h3 style="margin:0;">ä¸å¡ç»ä»¶</h3> |
| | | <IconButton |
| | | onClick={() => onAddWidget(1)} |
| | | icon="add-p" |
| | | status="add" |
| | | > |
| | | æ·»å |
| | | </IconButton> |
| | | </div> |
| | | <div class={styles.list}> |
| | | {local.value.length ? ( |
| | | local.value.map((item) => ( |
| | | <div class={styles.item}> |
| | | <div class={styles.itemContent}> |
| | | <span class={styles.span}>{menuMap[item]?.name}</span> |
| | | </div> |
| | | <el-tag>{item}</el-tag> |
| | | </div> |
| | | )) |
| | | ) : ( |
| | | <el-empty style="margin-left: 39%;" /> |
| | | )} |
| | | </div> |
| | | </div> |
| | | </div> |
| | | </BaseDialog> |
| | | <BaseDialog |
| | | title="æ·»å ç»ä»¶" |
| | | v-model={baseVisible.value} |
| | | onConfirm={onBaseConfirm} |
| | | onClose={onBaseClose} |
| | | > |
| | | <DyForm |
| | | v-model:formData={formData.value} |
| | | ref={formRef} |
| | | formItemProps={[ |
| | | { |
| | | prop: 'widgetName', |
| | | label: 'ç»ä»¶åç§°', |
| | | el: 'input', |
| | | placeholder: '请è¾å
¥ç»ä»¶åç§°', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: '请è¾å
¥ç»ä»¶åç§°', |
| | | }, |
| | | ], |
| | | }, |
| | | { |
| | | prop: 'widgetId', |
| | | label: 'ç»ä»¶ID', |
| | | placeholder: 'ProcessManagement', |
| | | el: 'input', |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: '请è¾å
¥ç»ä»¶ID', |
| | | }, |
| | | { |
| | | message: 'é¦åæ¯å¿
须为大åï¼ä¸è½ææ°ååç¹æ®ç¬¦å·', |
| | | pattern: /^[A-Z][A-Za-z]*$/, |
| | | trigger: 'blur', |
| | | }, |
| | | ], |
| | | }, |
| | | ]} |
| | | ></DyForm> |
| | | </BaseDialog> |
| | | </Fragment> |
| | | ) |
| | | } |
| | | }, |
| | | }) |