提交 7b360abb 编写于 作者: W wuyb@phxg.cn

页面刷新停留在当前页

上级 cad81cd8
...@@ -81,7 +81,7 @@ ...@@ -81,7 +81,7 @@
</template> </template>
<script> <script>
import {defineComponent, ref, reactive, toRaw, onMounted, computed, onUnmounted} from 'vue'; import {defineComponent, ref, reactive, toRaw, onMounted, nextTick, computed, watch, onUnmounted} from 'vue';
import moment from 'moment'; import moment from 'moment';
import {Form} from 'ant-design-vue'; import {Form} from 'ant-design-vue';
import {parseDate, formatObjDate} from '@/utils/util' import {parseDate, formatObjDate} from '@/utils/util'
...@@ -118,6 +118,7 @@ ...@@ -118,6 +118,7 @@
} }
// 设置验证规则 - 如果禁用表单则不校验 // 设置验证规则 - 如果禁用表单则不校验
if (item.required && !props.config.disabled) { if (item.required && !props.config.disabled) {
if (item.fieldName && !item.disabled) { if (item.fieldName && !item.disabled) {
let validator = typeof item.validator === 'function' ? item.validator : null let validator = typeof item.validator === 'function' ? item.validator : null
...@@ -141,6 +142,7 @@ ...@@ -141,6 +142,7 @@
} }
} }
} }
}); });
console.log('form - rules', rulesForm); console.log('form - rules', rulesForm);
console.log('form - formState', formState); console.log('form - formState', formState);
...@@ -222,9 +224,11 @@ ...@@ -222,9 +224,11 @@
return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0; return option.value.toLowerCase().indexOf(input.toLowerCase()) >= 0;
}; };
onMounted(() => { watch(() => props.config.data, (n) => {
initForm() if (n) {
}) initForm()
}
}, {deep: true, immediate: true})
return { return {
// //
......
import {ref, reactive, toRefs, computed} from 'vue' import {ref, reactive, toRefs, computed} from 'vue'
import {postAction, putAction, deleteAction, httpAction} from '@/api/commonApi/index'; import {postAction, putAction, deleteAction, httpAction} from '@/api/commonApi/index';
// 设置模态框 // 设置模态框
export function useModal(emit) { export function useModal({rowData}, emit) {
const useModalData = reactive({ const useModalData = reactive({
isShow: false, isShow: false,
confirmLoading: false confirmLoading: false
}) })
// 打开弹框
const onModalShow = () => { const onModalShow = () => {
console.log('打开弹框') console.log('打开弹框')
useModalData.isShow = true useModalData.isShow = true
console.log('modal - use', useModalData.isShow); console.log('modal - use', useModalData.isShow);
} }
// 确认
const modalOk = () => { const modalOk = () => {
console.log('确认') console.log('确认')
useModalData.isShow = false useModalData.isShow = false
} }
// 关闭
const modalCancel = () => { const modalCancel = () => {
console.log('modal - use - 取消') console.log('modal - use - 取消')
useModalData.isShow = false useModalData.isShow = false
...@@ -27,8 +30,17 @@ export function useModal(emit) { ...@@ -27,8 +30,17 @@ export function useModal(emit) {
emit('update:isShow', false) emit('update:isShow', false)
} }
// 修改 and 新增
/** 2022/5/10 14:49 @Description:
*
* @param url 接口链接
* @param formItem 参数
* @param otherValues 其他参数
* @param type add - edit
* @param path edit参数
*/
const handleOk = ({url,formItem, otherValues = {}, type = 'add', path}) => { const handleOk = ({url, formItem, otherValues = {}, type = 'add', path}) => {
useModalData.confirmLoading = true; useModalData.confirmLoading = true;
let axios; let axios;
let formData = Object.assign(formItem, otherValues); let formData = Object.assign(formItem, otherValues);
...@@ -61,6 +73,7 @@ export function useModal(emit) { ...@@ -61,6 +73,7 @@ export function useModal(emit) {
} }
// 根据屏幕变化,设置抽屉尺寸 // 根据屏幕变化,设置抽屉尺寸
// const resetScreenSize = () => { // const resetScreenSize = () => {
// const screenWidth = document.body.clientWidth; // const screenWidth = document.body.clientWidth;
...@@ -76,7 +89,8 @@ export function useModal(emit) { ...@@ -76,7 +89,8 @@ export function useModal(emit) {
modalCancel, modalCancel,
onModalShow, onModalShow,
...toRefs(useModalData), ...toRefs(useModalData),
handleOk handleOk,
} }
} }
......
...@@ -28,5 +28,5 @@ export default [ ...@@ -28,5 +28,5 @@ export default [
} }
] ]
}, },
{path: '/:pathToRegexp(.*)', hidden: true, redirect: '/'} //当用户输入页面链接错误或者没有该页面时,显示该路径页面 // {path: '/:pathToRegexp(.*)', hidden: true, redirect: '/'} //当用户输入页面链接错误或者没有该页面时,显示该路径页面
] ]
\ No newline at end of file
...@@ -5,12 +5,13 @@ ...@@ -5,12 +5,13 @@
<a-spin :spinning="confirmLoading"> <a-spin :spinning="confirmLoading">
<configForm :config="configListForm" ref="getQueryRef" @ok="query" @close="modalCancel"></configForm> <configForm :config="configListForm" ref="getQueryRef" @ok="query" @close="modalCancel"></configForm>
</a-spin> </a-spin>
<div ref="divRef">aaa</div>
</renderPopups> </renderPopups>
</template> </template>
<script> <script>
import {ref, reactive, watch, nextTick, onUnmounted} from 'vue' import {ref, reactive, watch, nextTick, onUnmounted, onMounted} from 'vue'
import {message} from 'ant-design-vue'
import modal from '@c/modal/index.vue' import modal from '@c/modal/index.vue'
import {renderPopups} from '@c/popups/popups' import {renderPopups} from '@c/popups/popups'
import {useModal} from "@/hook/useModal"; import {useModal} from "@/hook/useModal";
...@@ -19,7 +20,13 @@ ...@@ -19,7 +20,13 @@
export default { export default {
name: "fromModal", name: "fromModal",
props: { props: {
title: String title: String,
rowData: {
type: Array,
default: () => {
return {}
}
}
}, },
components: { components: {
modal, modal,
...@@ -27,10 +34,11 @@ ...@@ -27,10 +34,11 @@
configForm configForm
}, },
setup(props, {emit}) { setup(props, {emit}) {
const {onModalShow, isShow, modalCancel, handleOk, confirmLoading} = useModal(emit) const {onModalShow, isShow, modalCancel, handleOk, confirmLoading} = useModal(props, emit)
let spinning = ref(false) let spinning = ref(false)
const getQueryRef = ref() const getQueryRef = ref()
const divRef = ref()
const query = (data) => { const query = (data) => {
console.log('spinning', data); console.log('spinning', data);
handleOk({ handleOk({
...@@ -40,6 +48,7 @@ ...@@ -40,6 +48,7 @@
formItem: data formItem: data
}) })
} }
let configListForm = reactive({ let configListForm = reactive({
data: [ data: [
{ {
...@@ -86,27 +95,61 @@ ...@@ -86,27 +95,61 @@
} }
], ],
}) })
console.log('getQueryRef', getQueryRef);
console.log('divRef', divRef.value);
// 获取数据回显
watch(() => props.rowData, (n, o) => {
if (n) {
let rowObKey = Object.keys(n)
if (rowObKey.length > 0) {
configListForm.data.forEach(item => {
if (rowObKey.includes(item.fieldName)) {
item['defaultVal'] = props.rowData[item.fieldName]
}
})
}
}
})
const handlEdit = () => {
onModalShow()
// let rowObKey = Object.keys(props.rowData)
// if (rowObKey.length > 0) {
// configListForm.data.forEach(item => {
// if (rowObKey.includes(item.fieldName)) {
// item['defaultVal'] = props.rowData[item.fieldName]
// }
// })
// onModalShow()
// } else {
// message.error('参数不能为空')
// }
}
onMounted(() => {
console.log('ref - getQueryRef', getQueryRef);
})
watch(isShow, (n, o) => { watch(isShow, (n, o) => {
console.log('watch - isShow', n, o); if (!n) {
nextTick(() => { nextTick(() => {
console.log(getQueryRef); getQueryRef.value.resetForm()
console.log('resetForm - 页面关闭') })
getQueryRef.value.resetForm() }
})
}, {immediate: true}) })
return { return {
onModalShow, onModalShow,
isShow, isShow,
modalCancel, modalCancel,
handlEdit,
// //
confirmLoading, confirmLoading,
configListForm, configListForm,
getQueryRef, getQueryRef,
divRef, query,
query
} }
} }
} }
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</template> </template>
<template #action="{ record }"> <template #action="{ record }">
<div> <div>
<a>修改</a> <a @click="handlEdit(record)">修改</a>
<a-divider type="vertical"/> <a-divider type="vertical"/>
<a>删除</a> <a>删除</a>
<a-divider type="vertical"/> <a-divider type="vertical"/>
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
</a-table> </a-table>
</a-space> </a-space>
<fromModal ref="fromModalRef" title="jsx组价"></fromModal> <fromModal ref="fromModalRef" :rowData="rowData" title="新增"></fromModal>
</template> </template>
<script> <script>
...@@ -103,10 +103,19 @@ ...@@ -103,10 +103,19 @@
setup(props, {emit}) { setup(props, {emit}) {
const fromModalRef = ref() const fromModalRef = ref()
// 新增
const bindModalShow = () => { const bindModalShow = () => {
console.log(fromModalRef.value); console.log(fromModalRef.value);
fromModalRef.value.onModalShow() fromModalRef.value.onModalShow()
} }
let rowData = ref()
// 编辑
const handlEdit = (row) => {
rowData.value = row
fromModalRef.value.handlEdit()
}
const {dataSource} = useTable({ const {dataSource} = useTable({
dataAll: '/api/table/all' dataAll: '/api/table/all'
...@@ -121,6 +130,8 @@ ...@@ -121,6 +130,8 @@
fromModalRef, fromModalRef,
bindModalShow, bindModalShow,
handlEdit,
rowData
}; };
}, },
components: { components: {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册