来源列表及来源编辑

master
milo 2022-04-04 17:05:16 +08:00
parent f08c7251a8
commit 024c116a5a
3 changed files with 123 additions and 43 deletions

4
src/api/source.ts Normal file
View File

@ -0,0 +1,4 @@
import axios from 'axios'
import qs from 'qs'
export const sourceData = query => axios.post('http://oa-dxtc.test/source/index', qs.stringify(query));

4
src/api/sourceEdit.ts Normal file
View File

@ -0,0 +1,4 @@
import axios from 'axios'
import qs from 'qs'
export const sourceEdit = query => axios.post('http://oa-dxtc.test/source/edit', qs.stringify(query));

View File

@ -1,4 +1,5 @@
<template> <template>
<div>
<div class="crumbs"> <div class="crumbs">
<el-breadcrumb separator="/"> <el-breadcrumb separator="/">
<el-breadcrumb-item> <el-breadcrumb-item>
@ -41,14 +42,32 @@
</span> </span>
</template> </template>
</el-dialog> </el-dialog>
<!-- 编辑弹出框 -->
<el-dialog title="编辑" v-model="editVisible" width="40%">
<el-form :model="editForm" ref="tableEditData" :rules="rules" label-width="120px">
<el-form-item label="名称" prop="name">
<el-input v-model="editForm.name"></el-input>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="editVisible = false"> </el-button>
<el-button type="primary" @click="saveEdit"> </el-button>
</span>
</template>
</el-dialog>
</div>
</template> </template>
<script lang="ts"> <script lang="ts">
import { reactive, ref } from 'vue'; import { reactive, ref } from 'vue';
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { sourceAdd } from "../api/sourceAdd"; import { sourceAdd } from "../api/sourceAdd";
import { sourceEdit } from '../api/sourceEdit';
import { sourceData } from '../api/source';
export default { export default {
name: 'source', //name: 'source2',
setup() { setup() {
const listQuery = reactive({ const listQuery = reactive({
name: '' name: ''
@ -59,6 +78,16 @@ export default {
] ]
}); });
//
const tableData = ref([]);
const getData = () => {
sourceData(listQuery).then((res) => {
//console.log(res);
tableData.value = res.data.data;
});
}
getData();
// //
const addVisible = ref(false); const addVisible = ref(false);
const tableAddData = ref(null); const tableAddData = ref(null);
@ -86,6 +115,39 @@ export default {
}); });
}; };
//
const editVisible = ref(false);
const tableEditData = ref(null);
const editForm = reactive({
name : '',
id : 0
});
let idx = -1;
const handleEdit = (index, row) => {
idx = index;
Object.keys(editForm).forEach((item) => {
editForm[item] = row[item];
});
editVisible.value = true;
};
const saveEdit = () => {
tableEditData.value.validate((valid) => {
if(!valid){
ElMessage.error('验证失败');
return false;
}
sourceEdit(editForm).then((res) => {
if(res.data.code == 0){
ElMessage.success(`修改第 ${idx + 1} 行成功`);
editVisible.value = false;
}else{
ElMessage.error(res.data.msg);
return false;
}
});
});
};
return { return {
reactive, reactive,
listQuery, listQuery,
@ -94,7 +156,17 @@ export default {
tableAddData, tableAddData,
addForm, addForm,
handleAdd, handleAdd,
saveAdd saveAdd,
tableData,
getData,
sourceData,
editVisible,
tableEditData,
editForm,
idx,
handleEdit,
saveEdit,
sourceEdit
} }
} }