22 <div >
33 <!-- 列表页面 -->
44 <div class =" container" v-if =" !showEdit" >
5- <div class =" header" ><div class =" title" >图书列表</div ></div >
5+ <div class =" header" >
6+ <div class =" title" >图书列表</div >
7+ </div >
68 <!-- 表格 -->
7- <lin-table
8- :tableColumn =" tableColumn"
9- :tableData =" tableData"
10- :operate =" operate"
11- @handleEdit =" handleEdit"
12- @handleDelete =" handleDelete"
13- v-loading =" loading"
14- ></lin-table >
9+ <el-table :data =" books" v-loading =" loading" >
10+ <el-table-column type =" index" :index =" indexMethod" label =" 序号" ></el-table-column >
11+ <el-table-column prop =" title" label =" 书名" ></el-table-column >
12+ <el-table-column prop =" author" label =" 作者" ></el-table-column >
13+ <el-table-column label =" 操作" fixed =" right" width =" 275" >
14+ <template #default =" scope " >
15+ <el-button plain size =" mini" type =" primary" @click =" handleEdit(scope.row.id)" >编辑</el-button >
16+ <el-button
17+ plain
18+ size =" mini"
19+ type =" danger"
20+ @click =" handleDelete(scope.row.id)"
21+ v-permission =" { permission: '删除图书', type: 'disabled' }"
22+ >删除</el-button
23+ >
24+ </template >
25+ </el-table-column >
26+ </el-table >
1527 </div >
1628
1729 <!-- 编辑页面 -->
18- <book-modify v-else @editClose =" editClose" :editBookID = " editBookID " ></book-modify >
30+ <book-modify v-else @editClose =" editClose" :editBookId = " editBookId " ></book-modify >
1931 </div >
2032</template >
2133
2234<script >
23- import { reactive , onMounted , ref , toRefs } from ' vue'
35+ import { onMounted , ref } from ' vue'
2436import { ElMessageBox , ElMessage } from ' element-plus'
2537import bookModel from ' @/model/book'
26- import LinTable from ' @/component/base/table/lin-table'
27- import BookModify from ' ./book-modify'
38+ import BookModify from ' ./book'
2839
2940export default {
3041 components: {
31- LinTable,
3242 BookModify,
3343 },
3444 setup () {
35- const bookList = reactive ({
36- tableColumn: [
37- { prop: ' title' , label: ' 书名' },
38- { prop: ' author' , label: ' 作者' },
39- ],
40- operate: [
41- { name: ' 编辑' , func: ' handleEdit' , type: ' primary' },
42- {
43- name: ' 删除' ,
44- func: ' handleDelete' ,
45- type: ' danger' ,
46- permission: ' 删除图书' ,
47- },
48- ],
49- tableData: [],
50- loading: false ,
45+ const books = ref ([])
46+ const editBookId = ref (1 )
47+ const loading = ref (false )
48+ const showEdit = ref (false )
49+
50+ onMounted (() => {
51+ getBooks ()
5152 })
5253
5354 const getBooks = async () => {
5455 try {
55- bookList .loading = true
56- const books = await bookModel .getBooks ()
57- bookList .loading = false
58- bookList .tableData = books
56+ loading .value = true
57+ books .value = await bookModel .getBooks ()
58+ loading .value = false
5959 } catch (error) {
60- bookList . loading = false
60+ loading . value = false
6161 if (error .code === 10020 ) {
62- bookList . tableData = []
62+ books . value = []
6363 }
6464 }
6565 }
6666
67- onMounted (() => {
68- getBooks ()
69- })
70-
71- const showEdit = ref (false )
72- const editBookID = ref (1 )
73-
74- const handleEdit = val => {
67+ const handleEdit = id => {
7568 showEdit .value = true
76- editBookID .value = val . row . id
69+ editBookId .value = id
7770 }
7871
79- const handleDelete = val => {
72+ const handleDelete = id => {
8073 ElMessageBox .confirm (' 此操作将永久删除该图书, 是否继续?' , ' 提示' , {
8174 confirmButtonText: ' 确定' ,
8275 cancelButtonText: ' 取消' ,
8376 type: ' warning' ,
8477 }).then (async () => {
85- const res = await bookModel .delectBook (val . row . id )
78+ const res = await bookModel .delectBook (id)
8679 if (res .code < window .MAX_SUCCESS_CODE ) {
8780 getBooks ()
8881 ElMessage .success (` ${ res .message } ` )
@@ -95,12 +88,16 @@ export default {
9588 getBooks ()
9689 }
9790
91+ const indexMethod = index => index + 1
92+
9893 return {
99- ... toRefs (bookList),
94+ books,
95+ loading,
10096 showEdit,
101- editBookID,
10297 editClose,
10398 handleEdit,
99+ editBookId,
100+ indexMethod,
104101 handleDelete,
105102 }
106103 },
0 commit comments