表格跳转处理

This commit is contained in:
gary.fu
2024-01-04 11:40:56 +08:00
parent 5355e4fd3e
commit 33f7fc700b
4 changed files with 49 additions and 5 deletions

View File

@@ -55,7 +55,7 @@ const props = defineProps({
v-bind="column.linkAttrs"
@click="column.click(scope.row, scope)"
>
{{ scope.row[column.property] }}
{{ column.formatter?column.formatter(scope.row, scope):scope.row[column.property] }}
</el-link>
<slot
v-bind="scope"

View File

@@ -7,14 +7,23 @@
* @property {string} gender
* @property {Date} birthday
*/
import { $httpPost } from '@/vendors/axios'
import { $httpGet, $httpPost } from '@/vendors/axios'
/**
* 加载用户数据
* @return {{success:boolean, message:string,userList: [UserDto]}}
* @return {{success:boolean, message:string, resultData: {userList:[UserDto]}}}
*/
export const loadUsersResult = async (data, config) => {
const usersResult = await $httpPost('/api/users', data, config)
console.info('==================', usersResult)
return usersResult
}
/**
* 加载用户
* @return {{success:boolean, message:string, resultData: {user:UserDto}}}
*/
export const loadUserResult = async (id, config) => {
const usersResult = await $httpGet(`/api/users/${id}`, config)
console.info('==================', usersResult)
return usersResult
}

12
src/vendors/axios.js vendored
View File

@@ -51,3 +51,15 @@ export const $httpPost = (url, data, config) => {
}, reject)
})
}
export const $httpGet = (url, data, config) => {
return new Promise((resolve, reject) => {
$http.get(url, config).then(response => {
if (response.data) {
resolve(response.data) // 只要有数据就认为成功,内容再解析
} else {
reject(new Error('No response data'))
}
}, reject)
})
}

View File

@@ -1,7 +1,13 @@
<script setup>
import { ref } from 'vue'
import { onMounted, ref } from 'vue'
import { useRoute } from 'vue-router'
import { loadUserResult } from '@/services/user/UserService'
const userDto = ref({})
const route = useRoute()
const userDto = ref({
id: route.params.id
})
/**
* @type {[CommonFormOption]}
*/
@@ -46,6 +52,23 @@ const userFormOptions = [{
type: 'textarea'
}
}]
const loadUser = async () => {
console.info('============', route)
const id = route.params.id
if (id) {
const userResult = await loadUserResult(id)
if (userResult.success && userResult.resultData) {
const resultData = userResult.resultData
userDto.value = resultData.user
}
}
}
onMounted(() => {
loadUser()
})
const submitForm = form => {
form.validate(valid => {
if (valid) {