Преглед изворни кода

平台-区域管理接口对接

gzb
wangzhonglu пре 9 месеци
родитељ
комит
9a5f553cdb
4 измењених фајлова са 286 додато и 157 уклоњено
  1. 6
    0
      src/api/login.js
  2. 28
    3
      src/api/region.js
  3. 49
    79
      src/utils/index.js
  4. 203
    75
      src/views/platformSection/regionManage/regionManage.vue

+ 6
- 0
src/api/login.js Прегледај датотеку

@@ -0,0 +1,6 @@
1
+import { setRequest } from "@/utils/httpRequest";
2
+
3
+/**
4
+ * 生成短信验证码
5
+ */
6
+export const login_msg_code = (data) => setRequest("login/msg_code", data);

+ 28
- 3
src/api/region.js Прегледај датотеку

@@ -1,6 +1,31 @@
1
-import { region_url } from "@/utils/httpRequest";
1
+import { setRequest } from "@/utils/httpRequest";
2 2
 
3 3
 /**
4
- * 1.0.1管理员--账号登录
4
+ * 2.1区域--管理列表
5 5
  */
6
-export const admin_login = (data) => region_url("admin/login", data);
6
+export const region_list = (data) => setRequest("region/list", data);
7
+/**
8
+ * 2.1.2区域--选择列表
9
+ */
10
+export const region_list_sel = (data) => setRequest("region/list_sel", data);
11
+/**
12
+ * 2.2区域--添加
13
+ */
14
+export const region_add = (data) => setRequest("region/add", data);
15
+/**
16
+ * 2.3区域--更新
17
+ */
18
+export const region_edit = (data) => setRequest("region/edit", data);
19
+/**
20
+ * 2.4区域--删除
21
+ */
22
+export const region_delete = (data) => setRequest("region/delete", data);
23
+/**
24
+ * 2.5区域--详情
25
+ */
26
+export const region_detail = (data) => setRequest("region/detail", data);
27
+/**
28
+ * 2.5.2区域--管理员列表
29
+ */
30
+export const region_list_admin = (data) =>
31
+  setRequest("region/list_admin", data);

+ 49
- 79
src/utils/index.js Прегледај датотеку

@@ -336,89 +336,59 @@ export function hexToRgba(hex, opacity) {
336 336
   }
337 337
   return rgbaColor;
338 338
 }
339
-export const unitsDigit = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
340
-export const upperCaseLetters = [
341
-  "A",
342
-  "B",
343
-  "C",
344
-  "D",
345
-  "E",
346
-  "F",
347
-  "G",
348
-  "H",
349
-  "I",
350
-  "J",
351
-  "K",
352
-  "L",
353
-  "M",
354
-  "N",
355
-  "O",
356
-  "P",
357
-  "Q",
358
-  "R",
359
-  "S",
360
-  "T",
361
-  "U",
362
-  "V",
363
-  "W",
364
-  "X",
365
-  "Y",
366
-  "Z"
367
-];
368
-export const lowerCaseLetters = [
369
-  "a",
370
-  "b",
371
-  "c",
372
-  "d",
373
-  "e",
374
-  "f",
375
-  "g",
376
-  "h",
377
-  "i",
378
-  "j",
379
-  "k",
380
-  "l",
381
-  "m",
382
-  "n",
383
-  "o",
384
-  "p",
385
-  "q",
386
-  "r",
387
-  "s",
388
-  "t",
389
-  "u",
390
-  "v",
391
-  "w",
392
-  "x",
393
-  "y",
394
-  "z"
395
-];
396
-// 随机字母和数字组合
397
-export const getRandomPassword = (num = 6) => {
398
-  if (num <= 0) {
399
-    return "";
400
-  }
401
-  let passwordArr = [unitsDigit, upperCaseLetters, lowerCaseLetters];
402
-  let psw = "";
403
-  let numDigit = 0;
404
-  for (let i = 0; i < num; i++) {
405
-    let selectIndex = Math.floor(Math.random() * passwordArr.length);
406
-    if (selectIndex === 0) {
407
-      numDigit++;
339
+// 包含大小写字母和数字的随机组合
340
+export const generateRandomString = (n = 8) => {
341
+  let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
342
+  let result = "";
343
+  let hasUpperCase = false;
344
+  let hasLowerCase = false;
345
+  let hasDigit = false;
346
+  // 当n<3时,只需随机选择字符即可
347
+  if (n < 3) {
348
+    for (let i = 0; i < n; i++) {
349
+      result += chars.charAt(Math.floor(Math.random() * chars.length));
408 350
     }
409
-    if (numDigit === num && i === num - 1) {
410
-      let selectArr = [upperCaseLetters, lowerCaseLetters][
411
-        Math.floor(Math.random() * 2)
412
-      ];
413
-      psw += selectArr[Math.floor(Math.random() * selectArr.length)];
414
-    } else if (numDigit === 0 && i === num - 1) {
415
-      psw += unitsDigit[Math.floor(Math.random() * unitsDigit.length)];
351
+    return result;
352
+  }
353
+  // 当n>=3时,需要确保包含大写字母、小写字母和数字
354
+  while (result.length < n) {
355
+    let randomIndex = Math.floor(Math.random() * chars.length);
356
+    let randomChar = chars.charAt(randomIndex);
357
+
358
+    // 确保每种类型的字符至少被选中一次
359
+    if (hasUpperCase && hasLowerCase && hasDigit) {
360
+      result += randomChar;
416 361
     } else {
417
-      let selectArr = passwordArr[selectIndex];
418
-      psw += selectArr[Math.floor(Math.random() * selectArr.length)];
362
+      // 如果还没包含大写字母,并且当前字符是大写字母,则添加
363
+      if (!hasUpperCase && /[A-Z]/.test(randomChar)) {
364
+        result += randomChar;
365
+        hasUpperCase = true;
366
+      }
367
+      // 如果还没包含小写字母,并且当前字符是小写字母,则添加
368
+      else if (!hasLowerCase && /[a-z]/.test(randomChar)) {
369
+        result += randomChar;
370
+        hasLowerCase = true;
371
+      }
372
+      // 如果还没包含数字,并且当前字符是数字,则添加
373
+      else if (!hasDigit && /\d/.test(randomChar)) {
374
+        result += randomChar;
375
+        hasDigit = true;
376
+      }
377
+      // 否则跳过这个字符,重新选择
419 378
     }
420 379
   }
421
-  return psw;
380
+  // 如果字符串长度仍然小于n,则随机添加字符直到满足长度
381
+  while (result.length < n) {
382
+    result += chars.charAt(Math.floor(Math.random() * chars.length));
383
+  }
384
+  // 打乱结果字符串的顺序以确保随机性
385
+  result = result
386
+    .split("")
387
+    .sort(function () {
388
+      return 0.5 - Math.random();
389
+    })
390
+    .join("");
391
+  return result;
422 392
 };
423 393
 /**
424 394
  * 提取html字符串中的文字

+ 203
- 75
src/views/platformSection/regionManage/regionManage.vue Прегледај датотеку

@@ -12,12 +12,6 @@
12 12
     </div>
13 13
     <div class="table_wrap">
14 14
       <Table :columns="columns" :data="searchForm.list">
15
-        <template slot-scope="{ row }" slot="createtimeSlot">
16
-          <div>{{ date_format(row.createtime) }}</div>
17
-        </template>
18
-        <template slot-scope="{ row }" slot="updatetimeSlot">
19
-          <div>{{ date_format(row.updatetime) }}</div>
20
-        </template>
21 15
         <template slot-scope="{ row }" slot="actionSlot">
22 16
           <div class="action_list">
23 17
             <div @click="toEnter(row)">进入</div>
@@ -49,6 +43,7 @@
49 43
       title="新建"
50 44
     >
51 45
       <Form
46
+        v-if="regionInfo.show"
52 47
         ref="addForm"
53 48
         :model="regionInfo"
54 49
         :rules="rules"
@@ -61,9 +56,15 @@
61 56
             placeholder="请输入区域名称"
62 57
           ></Input>
63 58
         </FormItem>
59
+        <FormItem label="区域码" prop="regionCode" style="width: 100%">
60
+          <Input
61
+            v-model="regionInfo.regionCode"
62
+            placeholder="请输入区域码"
63
+          ></Input>
64
+        </FormItem>
64 65
         <FormItem
65 66
           label="管理员名称"
66
-          prop="admin"
67
+          prop="aname"
67 68
           style="width: calc(50% - 10px)"
68 69
         >
69 70
           <Input
@@ -110,15 +111,45 @@
110 111
         >
111 112
           <Input
112 113
             style="width: calc(100% - 102px)"
113
-            v-model="regionInfo.msgcode"
114
+            v-model="regionInfo.admin.msgcode"
114 115
             placeholder="请输入短信验证码"
115 116
           ></Input>
116
-          <div class="code_btn disabled">获取验证码</div>
117
+          <div
118
+            :class="['code_btn', regionInfo.second === 60 ? '' : 'disabled']"
119
+            @click="getMsgCode()"
120
+          >
121
+            获取验证码
122
+          </div>
123
+        </FormItem>
124
+        <FormItem label="地址" prop="address" style="width: 100%">
125
+          <Input
126
+            v-model="regionInfo.admin.address"
127
+            placeholder="请输入地址"
128
+          ></Input>
129
+        </FormItem>
130
+        <FormItem label="描述信息" prop="comm" style="width: 100%">
131
+          <Input
132
+            type="textarea"
133
+            v-model="regionInfo.admin.comm"
134
+            placeholder="请输入描述信息"
135
+          ></Input>
117 136
         </FormItem>
118 137
       </Form>
119
-      <div slot="footer">
120
-        <Button @click="regionInfo.show = false">取消</Button>
121
-        <Button @click="saveAddInfo()" type="primary">保存</Button>
138
+      <div
139
+        slot="footer"
140
+        style="
141
+          display: flex;
142
+          justify-content: space-between;
143
+          align-items: center;
144
+        "
145
+      >
146
+        <div style="color: #b50000">
147
+          注:密码必须包含大小写字母和数字的组合,长度在8-32之间。
148
+        </div>
149
+        <div>
150
+          <Button @click="regionInfo.show = false">取消</Button>
151
+          <Button @click="saveAddInfo()" type="primary">保存</Button>
152
+        </div>
122 153
       </div>
123 154
     </Modal>
124 155
     <!-- 查看 -->
@@ -128,7 +159,7 @@
128 159
       v-model="viewInfo.show"
129 160
       title="查看"
130 161
     >
131
-      <div class="view_title">河南星火燎原软件科技有限公司</div>
162
+      <div class="view_title">{{ viewInfo.regionName }}</div>
132 163
       <Table
133 164
         style="border: 1px solid #e8eaec; border-bottom: none"
134 165
         :columns="viewInfo.columns"
@@ -142,11 +173,41 @@
142 173
 </template>
143 174
 
144 175
 <script>
145
-import { date_format } from "@/utils";
176
+import { generateRandomString } from "@/utils";
177
+import {
178
+  region_list,
179
+  region_list_admin,
180
+  region_delete,
181
+  region_add
182
+} from "@/api/region";
146 183
 export default {
147 184
   data() {
185
+    const reg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,32}$/;
186
+    // 密码验证
187
+    const pwdCheck = (rule, value, callback) => {
188
+      if (!reg.test(this.regionInfo.admin.loginpwd)) {
189
+        return callback(
190
+          new Error("密码必须包含大小写字母和数字的组合,长度在8-32之间。")
191
+        );
192
+      } else {
193
+        callback();
194
+      }
195
+    };
196
+    // 重复密码验证
197
+    const pwdAgainCheck = async (rule, value, callback) => {
198
+      if (!reg.test(this.regionInfo.admin.loginpwd1)) {
199
+        return callback(
200
+          new Error("密码必须包含大小写字母和数字的组合,长度在8-32之间。")
201
+        );
202
+      } else if (
203
+        this.regionInfo.admin.loginpwd != this.regionInfo.admin.loginpwd1
204
+      ) {
205
+        return callback(new Error("两次输入密码不一致!"));
206
+      } else {
207
+        callback();
208
+      }
209
+    };
148 210
     return {
149
-      date_format,
150 211
       searchForm: {
151 212
         regionName: "",
152 213
         page: 1,
@@ -157,13 +218,20 @@ export default {
157 218
       // 新建
158 219
       regionInfo: {
159 220
         show: false,
221
+        // 验证码计时
222
+        timer: null,
223
+        second: 60,
160 224
         regionName: "",
225
+        regionCode: "",
161 226
         admin: {
162 227
           aname: "",
163 228
           loginname: "",
164 229
           loginpwd: "",
165 230
           loginpwd1: "",
166
-          phone: ""
231
+          phone: "",
232
+          msgcode: "",
233
+          address: "",
234
+          comm: ""
167 235
         }
168 236
       },
169 237
       // 查看
@@ -180,7 +248,7 @@ export default {
180 248
           },
181 249
           {
182 250
             title: "名称",
183
-            key: "admin",
251
+            key: "aname",
184 252
             align: "center"
185 253
           },
186 254
           {
@@ -203,7 +271,7 @@ export default {
203 271
             trigger: "blur"
204 272
           }
205 273
         ],
206
-        admin: [
274
+        aname: [
207 275
           {
208 276
             required: true,
209 277
             message: "请输入管理员名称",
@@ -217,17 +285,17 @@ export default {
217 285
             trigger: "blur"
218 286
           }
219 287
         ],
220
-        pwd: [
288
+        loginpwd: [
221 289
           {
222 290
             required: true,
223
-            message: "请输入密码",
291
+            validator: pwdCheck,
224 292
             trigger: "blur"
225 293
           }
226 294
         ],
227
-        pwd1: [
295
+        loginpwd1: [
228 296
           {
229 297
             required: true,
230
-            message: "请输入确认密码",
298
+            validator: pwdAgainCheck,
231 299
             trigger: "blur"
232 300
           }
233 301
         ]
@@ -259,7 +327,7 @@ export default {
259 327
         },
260 328
         {
261 329
           title: "创建时间",
262
-          slot: "createtimeSlot",
330
+          key: "createtime",
263 331
           width: 190,
264 332
           align: "center"
265 333
         },
@@ -271,7 +339,7 @@ export default {
271 339
         },
272 340
         {
273 341
           title: "操作时间",
274
-          slot: "updatetimeSlot",
342
+          key: "updatetime",
275 343
           width: 190,
276 344
           align: "center"
277 345
         },
@@ -288,6 +356,30 @@ export default {
288 356
     this.searchList();
289 357
   },
290 358
   methods: {
359
+    // 获取短信验证码
360
+    getMsgCode() {
361
+      if (this.regionInfo.second < 60) {
362
+        return;
363
+      }
364
+      // 手机号验证
365
+      if (!this.regionInfo.admin.phone) {
366
+        this.$Message.error("手机号码不能为空");
367
+        return;
368
+      }
369
+      let filter = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
370
+      if (!filter.test(this.regionInfo.admin.phone)) {
371
+        this.$Message.error("手机号码格式不正确");
372
+        return;
373
+      }
374
+      this.regionInfo.second = 60;
375
+      this.regionInfo.timer = setTimeout(() => {
376
+        this.regionInfo.second--;
377
+        if (this.regionInfo.second <= 0) {
378
+          clearTimeout(this.regionInfo.timer);
379
+          this.regionInfo.second = 60;
380
+        }
381
+      }, 1000);
382
+    },
291 383
     // 搜索
292 384
     searchList() {
293 385
       this.searchForm.page = 1;
@@ -306,48 +398,75 @@ export default {
306 398
     },
307 399
     // 获取列表
308 400
     getList() {
309
-      this.searchForm.list = [
310
-        {
311
-          regionid: 1,
312
-          regionName: "区域一",
313
-          createname: "区域一",
314
-          createtime: 1710838418,
315
-          updatename: "区域一",
316
-          updatetime: 1710838430
317
-        },
318
-        {
319
-          regionid: 2,
320
-          regionName: "区域二",
321
-          createname: "区域一",
322
-          createtime: 1710838418,
323
-          updatename: "区域一",
324
-          updatetime: 1710838430
325
-        },
326
-        {
327
-          regionid: 3,
328
-          regionName: "区域三",
329
-          createname: "区域一",
330
-          createtime: 1710838418,
331
-          updatename: "区域一",
332
-          updatetime: 1710838430
401
+      region_list({
402
+        page: this.searchForm.page,
403
+        size: this.searchForm.size,
404
+        regionName: this.searchForm.regionName
405
+      }).then((data) => {
406
+        if (data.code === 0) {
407
+          this.searchForm.list = data.obj.data;
408
+          this.searchForm.total = data.obj.total;
409
+        } else {
410
+          this.$Message.error(data.msg);
333 411
         }
334
-      ];
335
-      this.searchForm.total = 3;
412
+      });
336 413
     },
337 414
     // 新建
338 415
     toAdd() {
339
-      this.regionInfo.show = true;
340
-      this.regionInfo.regionName = "";
341
-      this.regionInfo.admin = "";
342
-      this.regionInfo.loginname = "";
343
-      this.regionInfo.pwd = "";
344
-      this.regionInfo.pwd1 = "";
345
-      this.regionInfo.phone = "";
346
-      this.regionInfo.code = "";
416
+      if (this.regionInfo.timer) {
417
+        clearTimeout(this.regionInfo.timer);
418
+        this.regionInfo.timer = null;
419
+      }
420
+      this.regionInfo = {
421
+        show: true,
422
+        // 验证码计时
423
+        timer: null,
424
+        second: 60,
425
+        regionName: "",
426
+        regionCode: "",
427
+        admin: {
428
+          aname: "",
429
+          loginname: "",
430
+          loginpwd: generateRandomString(8),
431
+          loginpwd1: "",
432
+          phone: "",
433
+          msgcode: "",
434
+          address: "",
435
+          comm: ""
436
+        }
437
+      };
347 438
     },
348 439
     // 保存新建
349 440
     saveAddInfo() {
350
-      this.regionInfo.show = false;
441
+      this.$refs.addForm.validate((valid) => {
442
+        if (valid) {
443
+          if (this.regionInfo.timer) {
444
+            clearTimeout(this.regionInfo.timer);
445
+            this.regionInfo.timer = null;
446
+          }
447
+          this.regionInfo.show = false;
448
+          region_add({
449
+            regionName: this.regionInfo.regionName,
450
+            regionCode: this.regionInfo.regionCode,
451
+            admin: {
452
+              aname: this.regionInfo.admin.aname,
453
+              loginname: this.regionInfo.admin.loginname,
454
+              loginpwd: this.regionInfo.admin.loginpwd,
455
+              phone: this.regionInfo.admin.phone,
456
+              msgcode: this.regionInfo.admin.msgcode,
457
+              address: this.regionInfo.admin.address,
458
+              comm: this.regionInfo.admin.comm
459
+            }
460
+          }).then((data) => {
461
+            if (data.code === 0) {
462
+              this.searchList();
463
+              this.$Message.success(data.msg);
464
+            } else {
465
+              this.$Message.error(data.msg);
466
+            }
467
+          });
468
+        }
469
+      });
351 470
     },
352 471
     // 进入
353 472
     toEnter() {
@@ -357,21 +476,18 @@ export default {
357 476
       });
358 477
     },
359 478
     // 查看
360
-    toView() {
361
-      this.viewInfo.show = true;
362
-      this.viewInfo.regionName = "河南星火燎原软件科技有限公司";
363
-      this.viewInfo.list = [
364
-        {
365
-          admin: "周文彦",
366
-          loginname: "zhouwenyan@xhkjedu.com",
367
-          phone: "15610230213"
368
-        },
369
-        {
370
-          admin: "齐思宇",
371
-          loginname: "zhouwenyan@xhkjedu.com",
372
-          phone: "15610230213"
479
+    toView(row) {
480
+      region_list_admin({
481
+        regionid: row.regionid
482
+      }).then((data) => {
483
+        if (data.code === 0) {
484
+          this.viewInfo.show = true;
485
+          this.viewInfo.regionName = row.regionName;
486
+          this.viewInfo.list = data.obj;
487
+        } else {
488
+          this.$Message.error(data.msg);
373 489
         }
374
-      ];
490
+      });
375 491
     },
376 492
     // 编辑
377 493
     toEdit(row) {
@@ -379,11 +495,23 @@ export default {
379 495
       this.regionInfo.regionid = row.regionid;
380 496
     },
381 497
     // 删除
382
-    toDel() {
498
+    toDel(row) {
383 499
       this.$Modal.confirm({
384 500
         title: "提示",
385 501
         content: "您确定删除选中数据吗?",
386
-        onOk: () => {},
502
+        onOk: () => {
503
+          region_delete({
504
+            regionid: row.regionid,
505
+            rversion: row.rversion
506
+          }).then((data) => {
507
+            if (data.code === 0) {
508
+              this.searchList();
509
+              this.$Message.success(data.msg);
510
+            } else {
511
+              this.$Message.error(data.msg);
512
+            }
513
+          });
514
+        },
387 515
         onCancel: () => {}
388 516
       });
389 517
     }

Loading…
Откажи
Сачувај