Browse Source

feat: 企微工具 - 平台管理 - "添加账号"前端页面

zhengxy 2 years ago
parent
commit
b8570fe5d4

+ 152 - 0
project/src/components/manage/platformManage/dialog/addAccountDialog.vue

@@ -0,0 +1,152 @@
1
+<template>
2
+  <el-dialog
3
+    :visible.sync="dialogVisible"
4
+    :before-close="handleCancel"
5
+    class="addAccount-dialog"
6
+    :title="dialogTitle"
7
+    width="450px"
8
+  >
9
+    <div class="form-wrap" v-loading="loading">
10
+      <div class="form-item">
11
+        <span class="lable"><em>*</em>账号</span>
12
+        <el-input v-model="form.accountNumber" size="small" placeholder="请输入账号" clearable />
13
+      </div>
14
+    </div>
15
+    <div slot="footer" class="dialog-footer">
16
+      <el-button size="mini" @click="handleCancel">取 消</el-button>
17
+      <el-button size="mini" type="primary" @click="handleConfirm" :disabled="loading">确 定</el-button>
18
+    </div>
19
+  </el-dialog>
20
+</template>
21
+
22
+<script>
23
+export default {
24
+  name: "addAccountDialog",
25
+  props: {
26
+    // 控制弹框是否显示
27
+    dialogVisible: {
28
+      type: Boolean,
29
+      default: () => false
30
+    },
31
+    // 账号所属的平台id
32
+    platformId: {
33
+      type: [String, Number],
34
+      default: () => ''
35
+    },
36
+  },
37
+  data() {
38
+    return {
39
+      loading: false,
40
+      form: {
41
+        accountNumber: '', // 账号
42
+      }
43
+    }
44
+  },
45
+  computed: {
46
+    // 当前操作是否为"编辑"
47
+    isEdit() {
48
+      return false // 暂时只有新建
49
+    },
50
+    // 弹框标题
51
+    dialogTitle() {
52
+      return this.isEdit ? '编辑账号' : '添加账号'
53
+    }
54
+  },
55
+  watch: {
56
+    dialogVisible(isShow) {
57
+      // 弹框显示 => 初始化表单数据
58
+      isShow && this.handleInitData()
59
+    },
60
+  },
61
+  methods: {
62
+    // 获取弹框表单数据
63
+    handleInitData() {
64
+      this.loading = false
65
+      if (this.isEdit) { // 编辑
66
+
67
+      } else { // 新建
68
+        this.form.accountNumber = ''
69
+      }
70
+    },
71
+    async handleConfirm() {
72
+      console.log('handleConfirm => ')
73
+      try {
74
+        // 表单校验
75
+        await this.handleFormValidate()
76
+        let url = `${this.URL.BASEURL}${this.URL.xxx}`
77
+        const params = {
78
+          ...this.form,
79
+          platformId: this.platformId
80
+        }
81
+
82
+        // if (this.isEdit) { // 编辑操作
83
+        //   url = `${this.URL.BASEURL}${this.URL.xxx}`
84
+        //   params.id = this.platformInfo.id
85
+        // }
86
+
87
+        console.log('url => ', url)
88
+        console.log('params => ', params)
89
+        this.$emit('confirm') // mock
90
+        return // mock
91
+
92
+        this.loading = true
93
+        const { data: res = {} } = await this.$axios.post(url, params)
94
+        if (res && res.errno == 0) {
95
+          this.$message.success('操作成功')
96
+          this.$emit('confirm')
97
+        } else if (res.errno != 4002) {
98
+          this.$message.warning(res.err || '操作失败')
99
+        }
100
+      } catch (error) {
101
+        console.log('error => ', error)
102
+      } finally {
103
+        this.loading = false
104
+      }
105
+    },
106
+    handleCancel() {
107
+      this.$emit('cancel')
108
+    },
109
+    // 执行表单校验
110
+    handleFormValidate() {
111
+      return new Promise((resolve, reject) => {
112
+        const { accountNumber } = this.form
113
+        if (!accountNumber) {
114
+          this.$message.warning('请输入账号')
115
+          reject('表单校验未通过')
116
+        } else {
117
+          resolve('表单校验通过')
118
+        }
119
+      })
120
+    },
121
+  },
122
+};
123
+</script>
124
+
125
+<style lang="scss" scoped>
126
+.addAccount-dialog {
127
+  .form-wrap {
128
+    padding: 0 10px;
129
+    .form-item {
130
+      display: flex;
131
+      align-items: center;
132
+      margin-top: 16px;
133
+      &:first-child {
134
+        margin-top: 0;
135
+      }
136
+      .lable {
137
+        width: 70px;
138
+        margin-right: 16px;
139
+        font-weight: 500;
140
+        flex-shrink: 0;
141
+        text-align: right;
142
+        em {
143
+          color: red;
144
+        }
145
+      }
146
+    }
147
+  }
148
+  .dialog-footer {
149
+    text-align: center;
150
+  }
151
+}
152
+</style>

+ 49 - 11
project/src/components/manage/platformManage/platformManage.vue

@@ -11,11 +11,10 @@
11 11
       <el-table-column label="描述" prop="name" min-width="160" align="center" />
12 12
       <el-table-column label="账号" min-width="300" align="center">
13 13
         <template slot-scope="{ row }">
14
-          <div class="account-wrap">
15
-            <span>123123123</span>
16
-            <i class="el-icon-delete" />
14
+          <div v-for="item in 3" :key="item" class="account-wrap">
15
+            <span>123123123<i class="del-btn el-icon-delete" /></span>
17 16
           </div>
18
-          <div class="account-add-btn">
17
+          <div class="account-add-btn" @click="onClickAddAccount(row)">
19 18
             <i class="el-icon-plus" />
20 19
             <span>添加账号</span>
21 20
           </div>
@@ -48,14 +47,25 @@
48 47
       @cancel="handleAddPlatformCancel"
49 48
     />
50 49
     <!-- E 添加平台 & 编辑平台 -->
50
+
51
+    <!-- S 添加账号 -->
52
+    <addAccountDialog
53
+      :dialogVisible="addAccountDialogVisible"
54
+      :platformId="currentAccountPlatformId"
55
+      @confirm="handleAddAccountConfirm"
56
+      @cancel="handleAddAccountCancel"
57
+    />
58
+    <!-- E 添加账号 -->
51 59
   </div>
52 60
 </template>
53 61
 <script>
54 62
 import addPlatformDialog from './dialog/addPlatformDialog.vue'
63
+import addAccountDialog from './dialog/addAccountDialog.vue'
55 64
 export default {
56 65
   name: 'platformManage',
57 66
   components: {
58 67
     addPlatformDialog,
68
+    addAccountDialog,
59 69
   },
60 70
   data () {
61 71
     return {
@@ -71,6 +81,9 @@ export default {
71 81
 
72 82
       addPlatformDialogVisible: false, // 控制"添加平台"弹框显示
73 83
       currentPlatformInfo: {}, // 当前编辑的平台信息
84
+
85
+      addAccountDialogVisible: false, // 控制"添加账号"弹框显示
86
+      currentAccountPlatformId: '', // 当前需要添加账号的平台id
74 87
     }
75 88
   },
76 89
   created () {
@@ -137,6 +150,23 @@ export default {
137 150
     },
138 151
     // E 添加 & 编辑平台
139 152
 
153
+    // S 添加账号
154
+    // 监听点击"添加账号"
155
+    onClickAddAccount(currentPlatform) {
156
+      this.currentAccountPlatformId = currentPlatform.id
157
+      this.addAccountDialogVisible = true
158
+    },
159
+    // 添加账号账号 => 确定
160
+    handleAddAccountConfirm() {
161
+      this.addAccountDialogVisible = false
162
+      this.handleGetPlatform()
163
+    },
164
+    // 添加账号账号 => 取消
165
+    handleAddAccountCancel() {
166
+      this.addAccountDialogVisible = false
167
+    },
168
+    // E 添加账号
169
+
140 170
     // S 禁用、启用平台
141 171
     // 监听点击"禁用"、"启用"按钮
142 172
     async onClickEnable(currentPlatform, eventCode) {
@@ -193,13 +223,21 @@ export default {
193 223
 }
194 224
 .platformManage-wrap {
195 225
   .account-wrap {
196
-    display: flex;
197
-    align-items: center;
198
-    justify-content: center;
199
-    i {
200
-      color: #F46C6C;
201
-      cursor: pointer;
202
-      margin-left: 4px;
226
+    span {
227
+      position: relative;
228
+      i {
229
+        position: absolute;
230
+        right: -14px;
231
+        top: 3px;
232
+        display: none;
233
+        color: #F46C6C;
234
+        cursor: pointer;
235
+      }
236
+    }
237
+    &:hover {
238
+      i {
239
+        display: inline-block;
240
+      }
203 241
     }
204 242
   }
205 243
   .account-add-btn {