From 5da038138e5629359939679936e68a65a077daca Mon Sep 17 00:00:00 2001
From: doum <doum>
Date: 星期五, 19 九月 2025 09:59:58 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
admin/src/components/base/BaseTable.vue | 109 ++++++++++++++++++++++++++++++++++++++----------------
1 files changed, 76 insertions(+), 33 deletions(-)
diff --git a/admin/src/components/base/BaseTable.vue b/admin/src/components/base/BaseTable.vue
index 7aea229..515df9e 100644
--- a/admin/src/components/base/BaseTable.vue
+++ b/admin/src/components/base/BaseTable.vue
@@ -1,5 +1,7 @@
<script>
import BasePage from './BasePage'
+import { isFunction } from 'element-ui'
+
export default {
name: 'BaseTable',
extends: BasePage,
@@ -43,7 +45,11 @@
}
},
methods: {
- // 閰嶇疆
+ /**
+ * 閰嶇疆
+ *
+ * @param extParams 閰嶇疆鍙傛暟
+ */
config (extParams) {
if (extParams == null) {
throw new Error('Parameter can not be null of method \'config\' .')
@@ -51,23 +57,21 @@
if (extParams.api == null) {
throw new Error('Missing config option \'api\'.')
}
-
- if(extParams.api.indexOf('@/',0) === 0){
- this.api = require(extParams.api)
- }else {
- this.api = require('@/api' + extParams.api)
- }
- // this.api = require('@/api' + extParams.api)
+ this.api = require('@/api' + extParams.api)
extParams.module && (this.module = extParams.module)
extParams['field.id'] && (this.configData['field.id'] = extParams['field.id'])
extParams['field.main'] && (this.configData['field.main'] = extParams['field.main'])
this.tableData.sorts = extParams.sorts
},
- // 鎼滅储
+ /**
+ * 鎼滅储锛堢偣鍑绘悳绱㈡寜閽椂瑙﹀彂锛�
+ */
search () {
this.handlePageChange(1)
},
- // 瀵煎嚭Excel
+ /**
+ * 瀵煎嚭Excel锛堢偣鍑诲鍑烘寜閽椂瑙﹀彂锛�
+ */
exportExcel () {
this.__checkApi()
this.$dialog.exportConfirm('纭瀵煎嚭鍚楋紵')
@@ -91,21 +95,38 @@
})
.catch(() => {})
},
- // 鎼滅储妗嗛噸缃�
+ /**
+ * 閲嶇疆鎼滅储鏉′欢锛堢偣鍑婚噸缃寜閽椂瑙﹀彂锛�
+ */
reset () {
this.$refs.searchForm.resetFields()
this.search()
},
- // 姣忛〉鏄剧ず鏁伴噺鍙樻洿澶勭悊
+ refresh () {
+ window.location.reload()
+ },
+ /**
+ * 椤靛閲忓彉鏇村鐞嗭紙鍒囨崲椤靛閲忔椂瑙﹀彂锛�
+ *
+ * @param pageSize 椤靛閲�
+ */
handleSizeChange (pageSize) {
this.tableData.pagination.pageSize = pageSize
this.search()
},
- // 琛岄�変腑澶勭悊
+ /**
+ * 琛岄�変腑澶勭悊锛堢偣鍑婚�変腑鍒楁椂瑙﹀彂锛�
+ *
+ * @param selectedRows 宸查�変腑鐨勮鏁扮粍
+ */
handleSelectionChange (selectedRows) {
this.tableData.selectedRows = selectedRows
},
- // 鎺掑簭
+ /**
+ * 鎺掑簭锛堢偣鍑诲垪澶存帓搴忔椂瑙﹀彂锛�
+ *
+ * @param sortData 鎺掑簭鍙傛暟
+ */
handleSortChange (sortData) {
this.tableData.sorts = []
if (sortData.order != null) {
@@ -116,7 +137,11 @@
}
this.handlePageChange()
},
- // 椤电爜鍙樻洿澶勭悊
+ /**
+ * 椤电爜鍙樻洿澶勭悊锛堝垎椤垫椂瑙﹀彂锛�
+ *
+ * @param pageIndex 鏂伴〉鐮�
+ */
handlePageChange (pageIndex) {
this.__checkApi()
this.tableData.pagination.pageIndex = pageIndex || this.tableData.pagination.pageIndex
@@ -132,31 +157,36 @@
this.tableData.pagination.total = data.total
})
.catch(e => {
- // this.$tip.apiFailed(e)
+ this.$tip.apiFailed(e)
})
.finally(() => {
this.isWorking.search = false
})
},
- // 鍒犻櫎
- deleteById (row, childConfirm = true) {
+ /**
+ * 鍒犻櫎锛堢偣鍑昏鎿嶄綔/鍒犻櫎鏃惰Е鍙戯級
+ *
+ * @param row 琛屽璞�
+ * @param childConfirm 鍒犻櫎瀛愯妭鐐规椂鏄惁杩涜浜屾纭
+ */
+ deleteById (row, childConfirm = true, call) {
this.__checkApi()
- // let message = `纭鍒犻櫎${this.module}銆�${row[this.configData['field.main']]}銆戝悧?`
- let message = `纭鍒犻櫎璇ヨ褰曞悧?`
+ let message = `纭鍒犻櫎${this.module}鍚�?`
if (childConfirm && row.children != null && row.children.length > 0) {
- // message = `纭鍒犻櫎${this.module}銆�${row[this.configData['field.main']]}銆戝強鍏跺瓙${this.module}鍚�?`
- message = `纭鍒犻櫎璇ヨ褰曞強鍏跺瓙鏁版嵁鍚�?`
+ message = `纭鍒犻櫎${this.module}銆�${row[this.configData['field.main']]}銆戝強鍏跺瓙${this.module}鍚�?`
}
this.$dialog.deleteConfirm(message)
.then(() => {
this.isWorking.delete = true
this.api.deleteById(row[this.configData['field.id']])
.then(() => {
- this.$tip.apiSuccess('鍒犻櫎鎴愬姛')
this.__afterDelete()
+ if (call) {
+ call()
+ }
})
.catch(e => {
- // this.$tip.apiFailed(e)
+ this.$tip.apiFailed(e)
})
.finally(() => {
this.isWorking.delete = false
@@ -165,10 +195,11 @@
.catch(() => {})
},
/**
- * 鎵归噺鍒犻櫎
- * @treeMode 鏄惁娣诲姞瀛愯妭鐐瑰垹闄ょ‘璁�
+ * 鎵归噺鍒犻櫎锛堢偣鍑绘壒閲忓垹闄ゆ椂瑙﹀彂锛�
+ *
+ * @param childConfirm 鍒犻櫎瀛愯妭鐐规椂鏄惁杩涜浜屾纭
*/
- deleteByIdInBatch (childConfirm = true) {
+ deleteByIdInBatch (childConfirm = true, call) {
this.__checkApi()
if (this.tableData.selectedRows.length === 0) {
this.$tip.warning('璇疯嚦灏戦�夋嫨涓�鏉℃暟鎹�')
@@ -183,19 +214,21 @@
}
}
if (containChildrenRows.length > 0) {
- message = '鏈灏嗗垹闄よ鏁版嵁鍙婂叾瀛愭暟鎹紝纭鍒犻櫎鍚楋紵'
+ message = `鏈灏嗗垹闄�${this.module}銆�${containChildrenRows.join('銆�')}銆戝強鍏跺瓙${this.module}璁板綍锛岀‘璁ゅ垹闄ゅ悧锛焋
}
}
this.$dialog.deleteConfirm(message)
.then(() => {
this.isWorking.delete = true
- this.api.deleteByIdInBatch(this.tableData.selectedRows.map(row => row.id).join(','))
+ this.api.deleteByIdInBatch(this.tableData.selectedRows.map(row => row[this.configData['field.id']]).join(','))
.then(() => {
- this.$tip.apiSuccess('鍒犻櫎鎴愬姛')
this.__afterDelete(this.tableData.selectedRows.length)
+ if (call) {
+ call()
+ }
})
.catch(e => {
- // this.$tip.apiFailed(e)
+ this.$tip.apiFailed(e)
})
.finally(() => {
this.isWorking.delete = false
@@ -203,8 +236,14 @@
})
.catch(() => {})
},
- // 鍒犻櫎澶勭悊
+ /**
+ * 鍒犻櫎鍚庡鐞嗭紝鍦ㄥ崟琛屽垹闄ゆ垨澶氳鍒犻櫎鍚庤皟鐢�
+ *
+ * @param deleteCount 鍒犻櫎鏁伴噺
+ * @private
+ */
__afterDelete (deleteCount = 1) {
+ this.$tip.apiSuccess('鍒犻櫎鎴愬姛')
// 鍒犻櫎褰撳墠椤垫渶鍚庝竴鏉¤褰曟椂鏌ヨ涓婁竴椤垫暟鎹�
if (this.tableData.list.length - deleteCount === 0) {
this.handlePageChange(this.tableData.pagination.pageIndex - 1 === 0 ? 1 : this.tableData.pagination.pageIndex - 1)
@@ -212,7 +251,11 @@
this.handlePageChange(this.tableData.pagination.pageIndex)
}
},
- // 妫�鏌ユ帴鍙f槸鍚﹂厤缃�
+ /**
+ * 妫�鏌ユ帴鍙f槸鍚﹂厤缃紝鍦ㄨ皟鐢ㄦ帴鍙f椂璋冪敤
+ *
+ * @private
+ */
__checkApi () {
if (this.api == null) {
throw new Error('The page is not initialized, you can use method \'this.config\' to initialize this page.')
--
Gitblit v1.9.3