Administrator.vue 16 KB

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