模版调整

This commit is contained in:
Jason 2022-08-12 18:54:09 +08:00
parent 3f092d3573
commit df39931b4b
2 changed files with 24 additions and 9 deletions

View File

@ -39,16 +39,24 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import type { FormInstance } from 'element-plus' import type { FormInstance } from 'element-plus'
import { postEdit, postAdd } from '@/api/org/post' import { postEdit, postAdd } from '@/api/org/post' //
import Popup from '@/components/popup/index.vue' import Popup from '@/components/popup/index.vue'
import feedback from '@/utils/feedback' import feedback from '@/utils/feedback'
import type { PropType } from 'vue'
defineProps({
dictData: {
type: Object as PropType<Record<string, any[]>>,
default: () => ({})
}
})
const emit = defineEmits(['success', 'close']) const emit = defineEmits(['success', 'close'])
const formRef = shallowRef<FormInstance>() const formRef = shallowRef<FormInstance>()
const popupRef = shallowRef<InstanceType<typeof Popup>>() const popupRef = shallowRef<InstanceType<typeof Popup>>()
const mode = ref('add') const mode = ref('add')
const popupTitle = computed(() => { const popupTitle = computed(() => {
return mode.value == 'edit' ? '编辑岗位' : '新增岗位' return mode.value == 'edit' ? '编辑岗位' : '新增岗位' //
}) })
//
const formData = reactive({ const formData = reactive({
id: '', id: '',
name: '', name: '',
@ -57,7 +65,7 @@ const formData = reactive({
remark: '', remark: '',
isStop: 1 isStop: 1
}) })
//
const formRules = { const formRules = {
code: [ code: [
{ {
@ -77,7 +85,7 @@ const formRules = {
const handleSubmit = async () => { const handleSubmit = async () => {
await formRef.value?.validate() await formRef.value?.validate()
mode.value == 'edit' ? await postEdit(formData) : await postAdd(formData) mode.value == 'edit' ? await postEdit(formData) : await postAdd(formData) //
popupRef.value?.close() popupRef.value?.close()
feedback.msgSuccess('操作成功') feedback.msgSuccess('操作成功')
emit('success') emit('success')

View File

@ -65,11 +65,17 @@
<pagination v-model="pager" @change="getLists" /> <pagination v-model="pager" @change="getLists" />
</div> </div>
</el-card> </el-card>
<edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" /> <edit-popup
v-if="showEdit"
ref="editRef"
:dict-data="dictData"
@success="getLists"
@close="showEdit = false"
/>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { postDelete, postLists } from '@/api/org/post' import { postDelete, postLists } from '@/api/org/post' //
import { useDictData } from '@/hooks/useDictOptions' import { useDictData } from '@/hooks/useDictOptions'
import { usePaging } from '@/hooks/usePaging' import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback' import feedback from '@/utils/feedback'
@ -77,17 +83,18 @@ import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>() const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false) const showEdit = ref(false)
const queryParams = reactive({ const queryParams = reactive({
//
code: '', code: '',
name: '', name: '',
isStop: '' isStop: ''
}) })
const { pager, getLists, resetPage, resetParams } = usePaging({ const { pager, getLists, resetPage, resetParams } = usePaging({
fetchFun: postLists, fetchFun: postLists, //
params: queryParams params: queryParams
}) })
// //
const { dictData } = useDictData<{ const { dictData } = useDictData<{
dict_sex: any[] dict_sex: any[]
}>(['dict_sex']) }>(['dict_sex'])
@ -106,7 +113,7 @@ const handleEdit = async (data: any) => {
} }
const handleDelete = async (id: number) => { const handleDelete = async (id: number) => {
await postDelete({ id }) await postDelete({ id }) // id
feedback.msgSuccess('删除成功') feedback.msgSuccess('删除成功')
getLists() getLists()
} }