123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <!--
- * @Author: fxs bjnsfxs@163.com
- * @Date: 2024-09-04 11:21:05
- * @LastEditors: fxs bjnsfxs@163.com
- * @LastEditTime: 2024-09-18 12:38:09
- * @FilePath: \Game-Backstage-Management-System\src\components\common\Dialog.vue
- * @Description:
- *
- -->
- <script setup lang="ts">
- import Form from '../form/Form.vue'
- import { useDialog } from '@/hooks/useDialog'
- import { nextTick, onMounted, reactive, ref } from 'vue'
- import type { DialogConfig } from '@/types/dialog'
- interface DialogProps {
- config: DialogConfig
- }
- // 临时用的close
- const { dialogClose2 } = useDialog()
- const emits = defineEmits(['formSubmit'])
- // 新增的URL与更新URL,因为有时候更新和新增在一起,有时候是分开的,所以在这里去区分
- const addUrl = ref<string>('')
- const updateUrl = ref<string>('')
- // 对话框ref
- const dialogFormRef = ref<InstanceType<typeof Form>>()
- // props
- const props = withDefaults(defineProps<DialogProps>(), {})
- // props中的关于配置的信息
- const dialogConfigInfo = props.config
- // 游戏配置对话框设置
- const dialogConfig = reactive({
- dialogVisible: false,
- title: '',
- formLabelWidth: '150px',
- type: 0 // 0 是新增 1是修改
- })
- // 游戏配置提交
- const submiteGameChange = () => {
- dialogFormRef.value?.submitFormData().then(() => {
- // console.log(dialogConfigInfo.reqConfig.otherOptions.formData.gid )
- dialogConfig.dialogVisible = false
- })
- }
- // 表单关闭
- const closeDialog = () => {
- dialogClose2(dialogFormRef.value, dialogConfig)
- }
- // 表单添加
- const addForm = () => {
- dialogConfigInfo.reqConfig.url = addUrl.value
- dialogConfig.dialogVisible = true
- }
- // 表单修改
- const editForm = (row: any, updateURL?: string) => {
- dialogConfig.dialogVisible = true
- if (updateURL) {
- updateUrl.value = updateURL
- dialogConfigInfo.reqConfig.url = updateUrl.value
- }
- nextTick(() => {
- dialogFormRef.value?.fillForm(row)
- })
- }
- onMounted(() => {
- dialogConfig.title = dialogConfigInfo.title
- addUrl.value = props.config.reqConfig.url // 保存一下新增的URL
- })
- /**
- * @description: 对字段进行加密
- * @param {*} fields 字段名
- * @param {*} useFormField 是否对表单的字段加密
- * @param {*} encryptMsg 加密的消息
- * @return {*}
- */
- const encrypt = (fields: string, useFormField: boolean, encryptMsg: Array<string>) => {
- dialogFormRef.value?.encryptData(fields, useFormField, encryptMsg).finally(() => {
- dialogConfig.dialogVisible = false
- })
- }
- const subForm = () => {
- emits('formSubmit')
- }
- defineExpose({
- addForm,
- editForm,
- encrypt
- })
- </script>
- <template>
- <div class="dialog">
- <el-dialog
- @close="closeDialog"
- v-model="dialogConfig.dialogVisible"
- :title="dialogConfig.title"
- :close-on-click-modal="false"
- style="width: 40%"
- append-to-body
- >
- <Form
- :disabled="true"
- @sub-form="subForm"
- ref="dialogFormRef"
- :config="{
- fieldsInfo: dialogConfigInfo.fieldsInfo,
- reqConfig: dialogConfigInfo.reqConfig,
- rules: dialogConfigInfo.rules
- }"
- ></Form>
- <template #footer>
- <div class="dialog-footer">
- <slot name="otherBtn"></slot>
- <slot name="btnGroup">
- <el-button class="dialogBtn" type="primary" @click="submiteGameChange()">
- 确认
- </el-button>
- <el-button class="dialogBtn" @click="closeDialog">取消</el-button>
- </slot>
- </div>
- </template>
- </el-dialog>
- </div>
- </template>
- <style scoped>
- .dialogBtn {
- box-sizing: border-box;
- margin-right: 10px;
- }
- </style>
|