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/BaseOpera.vue | 131 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 131 insertions(+), 0 deletions(-)
diff --git a/admin/src/components/base/BaseOpera.vue b/admin/src/components/base/BaseOpera.vue
new file mode 100644
index 0000000..4a364eb
--- /dev/null
+++ b/admin/src/components/base/BaseOpera.vue
@@ -0,0 +1,131 @@
+<script>
+export default {
+ name: 'BaseOpera',
+ data () {
+ return {
+ title: '',
+ visible: false,
+ isWorking: false,
+ // 鎺ュ彛
+ api: null,
+ // 閰嶇疆鏁版嵁
+ configData: {
+ 'field.id': 'id'
+ }
+ }
+ },
+ methods: {
+ /**
+ * 閰嶇疆
+ *
+ * @param extParams 閰嶇疆鍙傛暟
+ */
+ config (extParams = {}) {
+ if (extParams == null) {
+ throw new Error('Parameter can not be null of method \'config\' .')
+ }
+ if (extParams.api == null) {
+ throw new Error('Missing config option \'api\'.')
+ }
+ this.api = require('@/api' + extParams.api)
+ extParams['field.id'] && (this.configData['field.id'] = extParams['field.id'])
+ },
+ /**
+ * 鎵撳紑绐楀彛
+ *
+ * @param title 绐楀彛鏍囬
+ * @param target 琛屽璞★紙浠呯紪杈戦渶璇ュ弬鏁帮級
+ */
+ open (title, target) {
+ this.title = title
+ this.visible = true
+ // 鏂板缓
+ if (target == null) {
+ this.$nextTick(() => {
+ this.$refs.form.resetFields()
+ this.form[this.configData['field.id']] = null
+ })
+ return
+ }
+ // 缂栬緫
+ this.$nextTick(() => {
+ for (const key in this.form) {
+ this.form[key] = target[key]
+ }
+ })
+ },
+ /**
+ * 纭锛堢偣鍑荤‘璁ゆ寜閽悗瑙﹀彂锛�
+ */
+ confirm () {
+ if (this.form[this.configData['field.id']] == null || this.form[this.configData['field.id']] === '') {
+ this.__confirmCreate()
+ return
+ }
+ this.__confirmEdit()
+ },
+ /**
+ * 纭鏂板缓
+ *
+ * @private
+ */
+ __confirmCreate () {
+ this.$refs.form.validate((valid) => {
+ if (!valid) {
+ return
+ }
+ // 璋冪敤鏂板缓鎺ュ彛
+ this.isWorking = true
+ var that = this
+ this.api.create(this.form)
+ .then(() => {
+ // that.$tip.apiSuccess('鏂板缓鎴愬姛')
+ // that.$dialog.actionConfirmButton('鏄惁鍋滅暀璇ラ〉闈㈢户缁柊寤烘暟鎹紵', '鏂板缓鎴愬姛','缁х画娣诲姞','鍏抽棴杩斿洖')
+ // .then(() => {
+ that.$refs.form.resetFields()
+ that.visible = false
+ that.form[this.configData['field.id']] = null
+ that.$emit('success')
+ // })
+ // .catch(() => {
+ // that.visible = false
+ // that.$emit('success')
+ // })
+ })
+ .catch(e => {
+ this.$tip.apiFailed(e)
+ })
+ .finally(() => {
+ this.isWorking = false
+ })
+ })
+ },
+ /**
+ * 纭淇敼
+ *
+ * @private
+ */
+ __confirmEdit () {
+ this.$refs.form.validate((valid) => {
+ if (!valid) {
+ return
+ }
+ // 璋冪敤鏇存柊鎺ュ彛
+ this.isWorking = true
+ this.api.updateById(this.form)
+ .then(() => {
+ this.visible = false
+ this.$tip.apiSuccess('淇敼鎴愬姛')
+ this.$emit('success')
+ })
+ .catch(e => {
+ this.$tip.apiFailed(e)
+ })
+ .finally(() => {
+ this.isWorking = false
+ })
+ })
+ }
+ }
+}
+</script>
--
Gitblit v1.9.3