Administrator.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <template>
  2. <div class="card-container">
  3. <el-form
  4. :model="settingsForm"
  5. :rules="rule"
  6. v-loading="loading"
  7. ref="settingsForm"
  8. label-position="right"
  9. label-width="110px">
  10. <div class="flexr">
  11. <div class="card-content">
  12. <div class="section-title">
  13. <span style="padding-right: 30px;">Mail Notification Settings</span>
  14. <el-checkbox v-model="settingsForm.enabled">Enable notifications</el-checkbox>
  15. </div>
  16. <el-form-item
  17. label="Protocol:"
  18. prop="protocol">
  19. <el-input
  20. class="add-text"
  21. v-model="settingsForm.protocol"
  22. placeholder=""
  23. maxlength="10"/>
  24. </el-form-item>
  25. <el-form-item
  26. label="Host:"
  27. prop="host">
  28. <el-input
  29. class="add-text"
  30. v-model="settingsForm.host"
  31. placeholder=""
  32. maxlength="30"/>
  33. </el-form-item>
  34. <el-form-item
  35. label="Port:"
  36. prop="port">
  37. <el-input
  38. class="add-text"
  39. v-model="settingsForm.port"
  40. placeholder=""
  41. maxlength="5"/>
  42. </el-form-item>
  43. <el-form-item
  44. label="From:"
  45. prop="from">
  46. <el-input
  47. class="add-text"
  48. v-model="settingsForm.from"
  49. placeholder=""
  50. maxlength="50"/>
  51. </el-form-item>
  52. <el-form-item
  53. label="Username:"
  54. prop="username">
  55. <el-input
  56. class="add-text"
  57. v-model="settingsForm.username"
  58. placeholder=""
  59. maxlength="30"/>
  60. </el-form-item>
  61. <el-form-item
  62. label="Password:"
  63. prop="password">
  64. <div class="add-text flexcr" style="margin: -5px 0;">
  65. <div class="flex1">
  66. <el-input
  67. ref="password"
  68. class="add-text"
  69. :type="passwordType"
  70. v-model="settingsForm.password"
  71. placeholder="Email password"
  72. maxlength="128"/>
  73. <span class="show-pwd" @click="showPwd">
  74. <svg-icon :icon-class="passwordType === 'password' ? 'eye' : 'eye-open'" />
  75. </span>
  76. </div>
  77. <div class="divide10"></div>
  78. <el-button
  79. type="primary"
  80. @click="sendTestMail"
  81. style="margin: 5px 0;">
  82. Send Test Mail
  83. </el-button>
  84. </div>
  85. </el-form-item>
  86. <el-form
  87. :model="this"
  88. :rules="rule"
  89. ref="recipForm"
  90. label-width="110px"
  91. label-position="right">
  92. <el-form-item
  93. label="Recipients:"
  94. prop="recipient">
  95. <div class="add-text flexcr" style="margin: -5px 0;">
  96. <div class="flex1">
  97. <el-input
  98. class="add-text"
  99. v-model="recipient"
  100. placeholder=""
  101. maxlength="50"/>
  102. </div>
  103. <div class="divide10"></div>
  104. <el-button
  105. type="primary"
  106. icon="el-icon-plus"
  107. @click="addRecipient"
  108. style="margin: 5px 0;">
  109. Add
  110. </el-button>
  111. </div>
  112. </el-form-item>
  113. </el-form>
  114. <el-form-item
  115. label=""
  116. prop="chargeBoxId"
  117. label-width="0">
  118. <label class="el-form-item__label">Added Recipients:</label>
  119. <div class="receip-item" v-for="(item, index) in settingsForm.recipients" :key="index">
  120. <span>{{item}}</span>
  121. <i class="el-icon-close" @click="deleteRecipient(index)"></i>
  122. </div>
  123. <div
  124. class="link-button"
  125. v-if="settingsForm.recipients.length > 0"
  126. @click="clearAllRecipient">Clear All</div>
  127. <div class="el-form-item__error" v-else-if="manualValid">Please add at least one recipient</div>
  128. </el-form-item>
  129. </div>
  130. <div class="card-content">
  131. <div class="section-title">
  132. <span style="padding-right: 10px;">Notification Types</span>
  133. </div>
  134. <el-checkbox-group
  135. class="features-group"
  136. v-model="settingsForm.enabledFeatures">
  137. <template v-for="(item, index) in features">
  138. <el-checkbox
  139. :key="index"
  140. :label="item.value">{{item.name}}</el-checkbox>
  141. </template>
  142. </el-checkbox-group>
  143. </div>
  144. </div>
  145. <div class="card-content">
  146. <div class="buttons">
  147. <el-button
  148. type="primary"
  149. class="cancel-button"
  150. @click="clearAllField">
  151. Clear All
  152. </el-button>
  153. <el-button
  154. style="margin-left: 20px;"
  155. type="primary"
  156. @click="handleUpateButton">
  157. Update Changes
  158. </el-button>
  159. </div>
  160. </div>
  161. </el-form>
  162. </div>
  163. </template>
  164. <script>
  165. import api from '@/http/api/settings'
  166. import site from '@/http/api/site'
  167. export default {
  168. data() {
  169. return {
  170. loading: true,
  171. settingsForm: {
  172. enabled: false,
  173. recipients: [],
  174. //chargeTypes: [],
  175. enabledFeatures: []
  176. },
  177. rule: {
  178. "heartbeat": {
  179. required: true,
  180. trigger: 'blur',
  181. message: 'Please type heartbeat'
  182. },
  183. "expiration": {
  184. required: true,
  185. trigger: 'blur',
  186. message: 'Please type expiration'
  187. },
  188. "from": {
  189. required: true,
  190. trigger: 'blur',
  191. message: 'Please type from'
  192. },
  193. "host": {
  194. required: true,
  195. trigger: 'blur',
  196. message: 'Please type host'
  197. },
  198. "username": {
  199. required: true,
  200. trigger: 'blur',
  201. message: 'Please type username'
  202. },
  203. "password": {
  204. required: true,
  205. trigger: 'blur',
  206. message: 'Please type password'
  207. },
  208. "protocol": {
  209. required: true,
  210. trigger: 'blur',
  211. message: 'Please type protocol'
  212. },
  213. "port": {
  214. required: true,
  215. trigger: 'blur',
  216. message: 'Please type port'
  217. },
  218. "recipient": {
  219. pattern: /^[a-zA-Z0-9]+[\S]+@[a-zA-Z0-9_-]+[\.][\Sa-zA-Z]+$/,
  220. trigger: 'blur',
  221. message: 'Please type a correct recipient'
  222. }
  223. },
  224. recipient: '',
  225. clearForm: {
  226. "heartbeat": '',
  227. "expiration": '',
  228. "enabled": false,
  229. "from": "",
  230. "host": "",
  231. "username": "",
  232. "password": "",
  233. "protocol": "",
  234. "port": '',
  235. "recipients": [],
  236. //chargeTypes: [],
  237. "enabledFeatures": []
  238. },
  239. features: [],
  240. manualValid: false,
  241. //chargeTypeOptions: [],
  242. passwordType: "password"
  243. }
  244. },
  245. created() {
  246. //this.init();
  247. this.getCheckList();
  248. },
  249. methods: {
  250. async getCheckList() {
  251. const res = await api.getFeatures();
  252. if (res.data && res.data.length > 0) {
  253. this.features = res.data;
  254. }
  255. //this.getChargeTypeOptions()
  256. this.getSettings();
  257. },
  258. async getSettings() {
  259. const res = await api.getSettings();
  260. if (res.data) {
  261. this.settingsForm = res.data;
  262. }
  263. this.loading = false;
  264. },
  265. init() {
  266. this.recipient = "";
  267. const info = JSON.parse(JSON.stringify(this.clearForm));
  268. this.settingsForm = info;
  269. this.addChargeType()
  270. this.manualValid = false;
  271. this.$forceUpdate();
  272. },
  273. checkedChange(checked, value) {
  274. const enabledFeatures = this.settingsForm.enabledFeatures;
  275. if (checked) {
  276. enabledFeatures.push(value)
  277. } else {
  278. const index = enabledFeatures.indexOf(value)
  279. if (index >= 0) {
  280. enabledFeatures.splice(index, 1)
  281. }
  282. }
  283. this.settingsForm.enabledFeatures = enabledFeatures;
  284. },
  285. addRecipient() {
  286. if (this.recipient) {
  287. this.$refs["recipForm"].validate(result => {
  288. if (result) {
  289. this.settingsForm.recipients.push(this.recipient);
  290. this.recipient = "";
  291. }
  292. });
  293. }
  294. },
  295. deleteRecipient(index) {
  296. this.settingsForm.recipients.splice(index, 1);
  297. },
  298. clearAllRecipient() {
  299. this.$confirm('Clear all recipients?', 'Prompt', {
  300. confirmButtonText: 'Confirm',
  301. cancelButtonText: 'Cancel',
  302. type: 'warning'
  303. }).then(res => {
  304. this.settingsForm.recipients = [];
  305. })
  306. },
  307. clearAllField() {
  308. this.$confirm('Clear all fields?', 'Prompt', {
  309. confirmButtonText: 'Confirm',
  310. cancelButtonText: 'Cancel',
  311. type: 'warning'
  312. }).then(res => {
  313. this.init();
  314. this.$refs['settingsForm'].clearValidate();
  315. this.$refs["recipForm"].clearValidate();
  316. });
  317. },
  318. sendTestMail() {
  319. this.$refs['settingsForm'].validate(result => {
  320. if (this.settingsForm.recipients.length == 0) {
  321. this.manualValid = true;
  322. return;
  323. }
  324. if (result) {
  325. this.loading = true;
  326. api.testMail(this.settingsForm).then(res => {
  327. this.loading = false;
  328. this.$message({
  329. message: 'Send test mail successfully',
  330. type: 'success'
  331. });
  332. }).catch(err => {
  333. this.loading = false;
  334. this.$message({
  335. message: err,
  336. type: 'error'
  337. })
  338. });
  339. }
  340. });
  341. },
  342. handleUpateButton() {
  343. this.$refs['settingsForm'].validate(result => {
  344. if (this.settingsForm.recipients.length == 0) {
  345. this.manualValid = true;
  346. return;
  347. }
  348. if (result) {
  349. this.loading = true;
  350. api.updateSettings(this.settingsForm).then(res => {
  351. this.loading = false;
  352. this.getSettings();
  353. this.$message({
  354. message: 'Save settings successfully',
  355. type: 'success'
  356. });
  357. }).catch(err => {
  358. this.loading = false;
  359. this.$message({
  360. message: err,
  361. type: 'error'
  362. })
  363. });
  364. }
  365. });
  366. },
  367. showPwd() {
  368. if (this.passwordType === 'password') {
  369. this.passwordType = 'text'
  370. } else {
  371. this.passwordType = 'password'
  372. }
  373. this.$nextTick(() => {
  374. this.$refs.password.focus()
  375. })
  376. },
  377. }
  378. }
  379. </script>
  380. <style lang='scss' scoped="scoped">
  381. @import '../../styles/variables.scss';
  382. .card-container {
  383. width: 100%;
  384. padding: 20px 60px;
  385. min-height: $mainAppMinHeight;
  386. overflow-x: auto;
  387. background-color: #F0F5FC;
  388. }
  389. .card-content {
  390. flex: 1;
  391. min-width: 500px;
  392. margin: 0 8px 16px;
  393. padding: 15px 50px;
  394. border-radius: 6px;
  395. background-color: white;
  396. }
  397. .section-title {
  398. color: #333;
  399. margin-top: 20px;
  400. margin-bottom: 30px;
  401. font-size: 14px;
  402. user-select: none;
  403. line-height: 24px;
  404. font-weight: 700;
  405. font-family: sans-serif;
  406. /* text-transform: uppercase; */
  407. }
  408. .add-text {
  409. width: 100%;
  410. min-width: 150px;
  411. max-width: 400px;
  412. }
  413. .add-text ::v-deep .el-textarea__inner {
  414. font-family: sans-serif;
  415. }
  416. .add-text.pwd ::v-deep .el-input__inner {
  417. padding-right: 30px;
  418. }
  419. .value-text {
  420. width: 100%;
  421. max-width: 280px;
  422. }
  423. .hr {
  424. height: 2px;
  425. margin: 10px -40px;
  426. background-color: #F0F5FC;
  427. }
  428. .hr-full {
  429. height: 2px;
  430. margin: 20px -80px;
  431. background-color: #F0F5FC;
  432. }
  433. .rate-list-view {
  434. display: flex;
  435. flex-wrap: wrap;
  436. align-items: center;
  437. }
  438. .rate-text {
  439. max-width: 150px;
  440. padding-right: 14px;
  441. }
  442. .list-item-icon {
  443. width: 30px;
  444. height: 30px;
  445. cursor: pointer;
  446. margin: 0 10px 22px;
  447. }
  448. .buttons {
  449. padding-top: 15px;
  450. padding-bottom: 15px;
  451. }
  452. .tips {
  453. color: #999;
  454. font-size: 12px;
  455. padding-left: 150px;
  456. padding-bottom: 20px;
  457. }
  458. .tips i {
  459. color: #333;
  460. font-weight: 500;
  461. font-style: normal;
  462. }
  463. ::v-deep .el-checkbox__input.is-checked + .el-checkbox__label {
  464. color: #333;
  465. }
  466. ::v-deep .el-checkbox__input.is-checked .el-checkbox__inner::after {
  467. border-color: $buttonText;
  468. }
  469. .el-checkbox + .el-checkbox {
  470. margin: 12px 0;
  471. }
  472. .link-button {
  473. color: #3179E4;
  474. font-size: 14px;
  475. cursor: pointer;
  476. margin: 0 -10px;
  477. padding: 0 10px;
  478. display: inline-block;
  479. white-space: nowrap;
  480. text-decoration: underline;
  481. }
  482. .receip-item {
  483. display: flex;
  484. align-items: center;
  485. font-size: 14px;
  486. line-height: 1em;
  487. padding-top: 10px;
  488. }
  489. .receip-item i {
  490. color: #666;
  491. padding: 0 10px;
  492. cursor: pointer;
  493. }
  494. .receip-item i:hover,
  495. .receip-item i:active,
  496. .link-button:hover {
  497. color: #ff5500;
  498. }
  499. .divide10 {
  500. width: 10px;
  501. }
  502. .features-group {
  503. min-width: 400px;
  504. }
  505. @media screen and (max-width: 800px) {
  506. .card-container {
  507. padding: 10px 20px;
  508. }
  509. .card-content {
  510. min-width: auto;
  511. padding: 15px 30px;
  512. }
  513. }
  514. @media screen and (max-width: 500px) {
  515. .card-container {
  516. padding: 0px;
  517. }
  518. .card-content {
  519. padding: 15px 20px;
  520. }
  521. .divide10 {
  522. display: none;
  523. }
  524. .features-group {
  525. min-width: 80vw;
  526. }
  527. }
  528. .el-checkbox-group .el-checkbox {
  529. display: flex;
  530. align-items: center;
  531. }
  532. .el-checkbox >>> .el-checkbox__input {
  533. height: 14px;
  534. line-height: 14px;
  535. }
  536. .el-checkbox >>> .el-checkbox__label {
  537. word-break: break-all;
  538. white-space: normal;
  539. }
  540. .show-pwd {
  541. width: 15px;
  542. color: #666;
  543. cursor: pointer;
  544. font-size: 14px;
  545. position: relative;
  546. margin-left: -24px;
  547. }
  548. </style>