فهرست منبع

fix: 支付参数

LaveyD 1 هفته پیش
والد
کامیت
582b06bbb1
3فایلهای تغییر یافته به همراه65 افزوده شده و 18 حذف شده
  1. 1 1
      package.json
  2. 49 1
      src/pages/systemSetting/payChannel/Modal.vue
  3. 15 16
      src/pages/systemSetting/payChannel/index.vue

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "ticket",
-  "version": "1.0.17.4",
+  "version": "1.0.17.5",
   "private": true,
   "description": "售检票系统",
   "author": "",

+ 49 - 1
src/pages/systemSetting/payChannel/Modal.vue

@@ -17,6 +17,22 @@
         prop="name">
         <el-input v-model="form.name"></el-input>
       </el-form-item>
+      <el-form-item
+        v-if="type === 'edit'"
+        label="状态"
+        prop="status">
+        <el-select v-model="form.status">
+          <el-option label="激活" :value="1"></el-option>
+          <el-option label="禁用" :value="0"></el-option>
+        </el-select>
+      </el-form-item>
+      <el-form-item label="支付参数" prop="payParam" :error="payParamError">
+        <el-input
+          v-model="form.payParam"
+          type="textarea"
+          :rows="5"
+          placeholder="请输入JSON格式字符串,如:{&quot;key&quot;: &quot;value&quot;}"></el-input>
+      </el-form-item>
     </el-form>
     <span slot="footer">
       <el-button @click="visible= false">取 消</el-button>
@@ -31,9 +47,28 @@
 
 import { updatePayChannel, addPayChannel } from '@/api/payChannel'
 const defaultForm = {
-  name: ''
+  name: '',
+  payParam: ''
 }
 export default {
+  computed: {
+    payParamError () {
+      if (!this.form.payParam) return ''
+      try {
+        JSON.parse(this.form.payParam)
+        return ''
+      } catch (e) {
+        try {
+          // 兼容 key 无引号的 JS 对象字面量写法,先补双引号再解析
+          const fixed = this.form.payParam.replace(/(['"])?([a-zA-Z_\u4e00-\u9fa5]\w*)\1\s*:/g, '"$2":')
+          JSON.parse(fixed)
+          return ''
+        } catch (e2) {
+          return 'JSON格式不正确,请检查'
+        }
+      }
+    }
+  },
   data () {
     return {
       type: '',
@@ -62,6 +97,19 @@ export default {
     handleSubmit () {
       this.$refs.form.validate((valid) => {
         if (valid) {
+          if (this.form.payParam) {
+            try {
+              JSON.parse(this.form.payParam)
+            } catch (e) {
+              try {
+                const fixed = this.form.payParam.replace(/(['"])?([a-zA-Z_\u4e00-\u9fa5]\w*)\1\s*:/g, '"$2":')
+                JSON.parse(fixed)
+              } catch (e2) {
+                this.$message.error('支付参数必须是有效的JSON格式')
+                return
+              }
+            }
+          }
           if (this.type === 'edit') {
             updatePayChannel(this.form).then(res => {
               this.$message.success('操作成功')

+ 15 - 16
src/pages/systemSetting/payChannel/index.vue

@@ -117,23 +117,28 @@
           label="状态"
         >
           <template slot-scope="scope">
-            <el-switch
-              @change="handelStatusChange($event,scope.row)"
-              v-model="scope.row.status"
-              active-text="激活"
-              inactive-text="禁用"
-              :active-value="1"
-              :inactive-value="0">
-            </el-switch>
+            {{ scope.row.status === 1 ? '激活' : '禁用' }}
           </template>
         </el-table-column>
 
+        <el-table-column
+          prop="payParam"
+          label="支付参数"
+          :show-overflow-tooltip="true"
+          min-width="200"
+        >
+        </el-table-column>
+
         <el-table-column
           prop="action"
           label="操作"
           width="260"
         >
           <template slot-scope="scope">
+            <el-button
+              @click="$refs.modal.show('edit', scope.row)">
+              编辑
+            </el-button>
             <el-button
               v-if="scope.row.name === '工行支付'"
               @click="$refs.subMerchant.show(scope.row)">
@@ -172,7 +177,7 @@
 import Modal from './Modal.vue'
 import TicketSpot from './TicketSpot.vue'
 import SubMerchant from './SubMerchant.vue'
-import { getPayChannel, updatePayChannel, deletePayChannel } from '@/api/payChannel'
+import { getPayChannel, deletePayChannel } from '@/api/payChannel'
 
 const nameMap = {
   'POS': 'POS机',
@@ -245,13 +250,7 @@ export default {
       }).catch(() => {})
     },
     handelStatusChange (value, item) {
-      const newItem = Object.assign({}, { ...item, status: value })
-
-      updatePayChannel(newItem).then(res => {
-        this.$message.success('操作成功')
-        this.getList()
-        this.$store.dispatch('getPayChannel')
-      })
+      this.$refs.modal.show('edit', item)
     }
   }
 }