kongdeqiang
2022-11-04 98fcbf66162fba0a097a8abcaeba5e1c1e32000e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
<style lang="less">
@import "./settingManage.less";
</style>
<template>
  <div>
    <Card>
      <Layout>
        <Sider
          hide-trigger
          style="background: #fff; max-width: 220px; flex: 0 0 220px"
        >
          <Menu
            :active-name="currName"
            theme="light"
            width="auto"
            @on-select="currName = $event"
          >
            <MenuItem name="oss">文件对象存储配置</MenuItem>
            <!--<MenuItem name="sms">短信配置</MenuItem>-->
            <!--<MenuItem name="email">邮件配置</MenuItem>-->
            <!--<MenuItem name="vaptcha">Vaptcha验证码</MenuItem>-->
            <!--<MenuItem name="stopWord">禁用词管理</MenuItem>-->
            <!--<MenuItem name="notice">系统公告配置</MenuItem>-->
            <!--<MenuItem name="other">其他配置</MenuItem>-->
          </Menu>
        </Sider>
        <Content
          :style="{
            padding: '8px 40px',
            minHeight: '550px',
            background: '#fff',
          }"
        >
          <div v-show="currName == 'oss'">
            <div class="setting-title">文件对象存储配置</div>
            <oss />
          </div>
          <div v-show="currName == 'sms'">
            <div class="setting-title">短信配置</div>
            <sms />
          </div>
          <div v-show="currName == 'email'">
            <div class="setting-title">邮箱配置</div>
            <div style="display: flex; position: relative">
              <Form
                ref="emailForm"
                :model="email"
                :label-width="110"
                label-position="left"
                :rules="emailValidate"
              >
                <FormItem label="邮箱服务器" prop="host">
                  <Input
                    type="text"
                    v-model="email.host"
                    placeholder="请输入邮箱服务器Host,例如QQ邮箱为smtp.qq.com"
                    style="width: 380px"
                  />
                </FormItem>
                <FormItem label="发送邮箱账号" prop="username">
                  <Input
                    type="text"
                    v-model="email.username"
                    placeholder="请输入发送者Email账号"
                    style="width: 380px"
                  />
                </FormItem>
                <FormItem label="邮箱授权码" prop="password">
                  <Tooltip
                    placement="right"
                    content="无法编辑时请先点击查看图标"
                  >
                    <Input
                      class="input-see"
                      type="text"
                      v-model="email.password"
                      :readonly="!changedEmailPass"
                      @on-click="seeSecret('EMAIL_SETTING')"
                      icon="ios-eye"
                      placeholder="请输入邮箱授权码,进入邮箱-设置中可找到"
                      style="width: 380px"
                    />
                  </Tooltip>
                </FormItem>
                <FormItem>
                  <Button
                    type="primary"
                    style="width: 100px"
                    :loading="saveLoading"
                    @click="saveEditEmail"
                    >保存更改</Button
                  >
                </FormItem>
              </Form>
              <Spin fix v-if="loading"></Spin>
            </div>
          </div>
          <div v-show="currName == 'vaptcha'">
            <div class="setting-title">Vaptcha验证码配置</div>
            <div style="display: flex; position: relative">
              <Form
                ref="vaptchaForm"
                :model="vaptcha"
                :label-width="110"
                label-position="left"
                :rules="vaptchaValidate"
              >
                <FormItem label="VID" prop="vid">
                  <Input
                    type="text"
                    v-model="vaptcha.vid"
                    placeholder="请输入验证单元VID"
                    style="width: 380px"
                  />
                </FormItem>
                <FormItem label="secretKey" prop="secretKey">
                  <Tooltip
                    placement="right"
                    content="无法编辑时请先点击查看图标"
                  >
                    <Input
                      class="input-see"
                      type="text"
                      v-model="vaptcha.secretKey"
                      :readonly="!changedVaptchaSK"
                      @on-click="seeSecret('VAPTCHA_SETTING')"
                      icon="ios-eye"
                      placeholder="请输入验证单元Key"
                      style="width: 380px"
                    />
                  </Tooltip>
                </FormItem>
                <FormItem>
                  <Button
                    type="primary"
                    style="width: 100px"
                    :loading="saveLoading"
                    @click="saveEditVaptcha"
                    >保存更改</Button
                  >
                </FormItem>
              </Form>
              <Spin fix v-if="loading"></Spin>
            </div>
          </div>
          <div v-show="currName == 'stopWord'">
            <div class="setting-title">禁用词管理</div>
            <stop-word />
          </div>
          <div v-show="currName == 'notice'">
            <div class="setting-title">
              系统公告配置
              <Tooltip content="访问系统公告,右上角弹出" placement="right">
                <Icon
                  type="md-help-circle"
                  size="20"
                  color="#c5c5c5"
                  style="margin-left: 10px; cursor: pointer"
                />
              </Tooltip>
            </div>
            <div style="display: flex">
              <Form
                ref="noticeForm"
                :model="notice"
                :label-width="110"
                label-position="left"
              >
                <FormItem label="公告开关" prop="open">
                  <i-switch v-model="notice.open">
                    <span slot="open">开</span>
                    <span slot="close">关</span>
                  </i-switch>
                </FormItem>
                <FormItem label="展示时长" prop="duration">
                  <Tooltip
                    trigger="hover"
                    placement="right"
                    content="设为0不自动关闭"
                  >
                    <InputNumber
                      :max="1000"
                      :min="0"
                      v-model="notice.duration"
                    ></InputNumber
                    ><span style="margin-left: 5px">秒</span>
                  </Tooltip>
                </FormItem>
                <FormItem label="展示页面" prop="position">
                  <Select
                    v-model="notice.position"
                    placeholder="请选择"
                    style="width: 380px"
                  >
                    <Option value="LOGIN">登录页(访问系统时)</Option>
                    <Option value="HOME">首页(登录系统后)</Option>
                  </Select>
                </FormItem>
                <FormItem label="公告标题" prop="title">
                  <Input v-model="notice.title" style="width: 380px" />
                </FormItem>
                <FormItem label="公告内容" prop="content">
                  <Input
                    type="textarea"
                    v-model="notice.content"
                    :rows="4"
                    placeholder
                    style="width: 380px"
                  />
                </FormItem>
                <FormItem>
                  <Button
                    type="primary"
                    style="width: 100px"
                    :loading="saveLoading"
                    @click="saveEditNotice"
                    >保存更改</Button
                  >
                </FormItem>
              </Form>
              <Spin fix v-if="loading"></Spin>
            </div>
          </div>
          <div v-show="currName == 'other'">
            <div class="setting-title">其他配置</div>
            <div style="display: flex">
              <Form
                ref="otherForm"
                :model="other"
                :label-width="110"
                label-position="left"
                :rules="otherValidate"
              >
                <FormItem label="应用部署域名" prop="domain">
                  <Tooltip placement="right" content="拼接部分资源访问链接使用">
                    <Input
                      type="text"
                      v-model="other.domain"
                      placeholder="请输入应用部署域名前缀,如http://xboot.exrick.cn"
                      style="width: 380px"
                    />
                  </Tooltip>
                </FormItem>
                <FormItem label="单点登录域名" prop="ssoDomain">
                  <Tooltip
                    max-width="250"
                    transfer
                    placement="right"
                    content="该域名及子域名下将可获得单点登录所需数据"
                  >
                    <Input
                      type="text"
                      v-model="other.ssoDomain"
                      placeholder="请输入应用部署一级域名,如exrick.cn"
                      style="width: 380px"
                    />
                  </Tooltip>
                </FormItem>
                <FormItem label="IP黑名单" prop="blacklist">
                  <Input
                    type="textarea"
                    v-model="other.blacklist"
                    :rows="4"
                    placeholder="多个以回车分隔"
                    style="width: 380px"
                  />
                </FormItem>
                <FormItem>
                  <Button
                    type="primary"
                    style="width: 100px"
                    :loading="saveLoading"
                    @click="saveEditOther"
                    >保存更改</Button
                  >
                </FormItem>
              </Form>
              <Spin fix v-if="loading"></Spin>
            </div>
          </div>
        </Content>
      </Layout>
    </Card>
  </div>
</template>
 
<script>
import {
  seeSecretSet,
  getEmailSet,
  editEmailSet,
  getVaptchaSet,
  editVaptchaSet,
  getOtherSet,
  editOtherSet,
  getNoticeSet,
  editNoticeSet
} from "@/api/index";
import oss from "./oss.vue";
import sms from "./sms.vue";
import stopWord from "./stopWord.vue";
export default {
  name: "setting-manage",
  components: {
    oss,
    sms,
    stopWord,
  },
  data() {
    return {
      currName: "oss",
      loading: false, // 表单加载状态
      saveLoading: false,
      email: {
        host: "",
        username: "",
        password: "",
      },
      changedEmailPass: false, // 是否修改邮件密码
      vaptcha: {
        vID: "",
        secretKey: "",
      },
      changedVaptchaSK: false, // 是否修改Vaptcha的secrectKey
      notice: {
        duration: 10,
      },
      other: {
        domain: "http://127.0.0.1:8888",
        ssoDomain: "",
        blacklist: "",
      },
      emailValidate: {
        // 表单验证规则
        host: [{ required: true, message: "不能为空", trigger: "change" }],
        username: [{ required: true, message: "不能为空", trigger: "change" }],
        password: [{ required: true, message: "不能为空", trigger: "change" }],
      },
      vaptchaValidate: {
        // 表单验证规则
        vid: [{ required: true, message: "不能为空", trigger: "change" }],
        secretKey: [{ required: true, message: "不能为空", trigger: "change" }],
      },
      otherValidate: {
        // 表单验证规则
        domain: [{ required: true, message: "不能为空", trigger: "change" }],
      },
      
    };
  },
  methods: {
    init() {
      this.initEmailSet();
      this.initVaptchaSet();
      this.initNoticeSet();
      this.initOtherSet();
    },
    initEmailSet() {
      this.loading = true;
      getEmailSet().then((res) => {
        this.loading = false;
        if (res.result) {
          // 转换null为""
          for (let attr in res.result) {
            if (res.result[attr] == null) {
              res.result[attr] = "";
            }
          }
          this.email = res.result;
        } else {
          this.changedEmailPass = true;
        }
      });
    },
    initVaptchaSet() {
      this.loading = true;
      getVaptchaSet().then((res) => {
        this.loading = false;
        if (res.result) {
          // 转换null为""
          for (let attr in res.result) {
            if (res.result[attr] == null) {
              res.result[attr] = "";
            }
          }
          this.vaptcha = res.result;
        } else {
          this.changedVaptchaSK = true;
        }
      });
    },
    initOtherSet() {
      this.loading = true;
      getOtherSet().then((res) => {
        this.loading = false;
        if (res.result) {
          // 转换null为""
          for (let attr in res.result) {
            if (res.result[attr] == null) {
              res.result[attr] = "";
            }
          }
          this.other = res.result;
        }
      });
    },
    initNoticeSet() {
      this.loading = true;
      getNoticeSet().then((res) => {
        this.loading = false;
        if (res.result) {
          // 转换null为""
          for (let attr in res.result) {
            if (res.result[attr] == null) {
              res.result[attr] = "";
            }
          }
          this.notice = res.result;
        }
      });
    },
    seeSecret(name) {
      if (!name) {
        return;
      }
      seeSecretSet(name).then((res) => {
        if (res.success) {
          if (this.currName == "sms") {
            this.sms.secretKey = res.result;
            this.changedSmsSK = true;
          } else if (this.currName == "email") {
            this.email.password = res.result;
            this.changedEmailPass = true;
          } else if (this.currName == "vaptcha") {
            this.vaptcha.secretKey = res.result;
            this.changedVaptchaSK = true;
          }
        }
      });
    },
    saveEditEmail() {
      this.$refs.emailForm.validate((valid) => {
        if (valid) {
          this.saveLoading = true;
          this.email.changed = this.changedEmailPass;
          editEmailSet(this.email).then((res) => {
            this.saveLoading = false;
            if (res.success) {
              this.$Message.success("保存成功");
            }
          });
        }
      });
    },
    saveEditVaptcha() {
      this.$refs.vaptchaForm.validate((valid) => {
        if (valid) {
          this.saveLoading = true;
          this.vaptcha.changed = this.changedVaptchaSK;
          editVaptchaSet(this.vaptcha).then((res) => {
            this.saveLoading = false;
            if (res.success) {
              this.$Message.success("保存成功");
            }
          });
        }
      });
    },
    saveEditOther() {
      this.$refs.otherForm.validate((valid) => {
        if (valid) {
          this.saveLoading = true;
          editOtherSet(this.other).then((res) => {
            this.saveLoading = false;
            if (res.success) {
              this.$Message.success("保存成功");
            }
          });
        }
      });
    },
    saveEditNotice() {
      this.saveLoading = true;
      let str = JSON.stringify(this.notice);
      let params = JSON.parse(str);
      if (!this.notice.duration) {
        params.duration = 0;
      }
      editNoticeSet(params).then((res) => {
        this.saveLoading = false;
        if (res.success) {
          this.$Message.success("保存成功");
        }
      });
    },
  },
  mounted() {
    let name = this.$route.query.name;
    if (name) {
      this.currName = name;
    }
    this.init();
  },
};
</script>