UserParameters.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <template>
  2. <Navbar :title="$t('lang.UserParameters.personalSettings')" :is-go-back="true" />
  3. <div style="margin-top: 2rem;" class="container">
  4. <div>
  5. <!-- <div
  6. class="row m-row"
  7. style="margin-top:10px"
  8. >
  9. <div class="col-md-12">
  10. <h4 class="title page-header">用户角色<span class="label label-warning title-addon">{{ loginInfo.roleName }}</span></h4>
  11. </div>
  12. </div> -->
  13. <div
  14. class="row m-row"
  15. >
  16. <div class="col-md-12">
  17. <h4 class="title page-header">{{ $t("lang.UserParameters.userAvatar") }}</h4>
  18. <div>
  19. <ImageUpload
  20. v-model="loginUserDto.imageName"
  21. :class-name="'com.leanwo.prodog.base.model.User'"
  22. @update:model-value="uploadUserImage"
  23. />
  24. </div>
  25. </div>
  26. </div>
  27. <div
  28. class="row m-row"
  29. >
  30. <div class="col-md-12">
  31. <h4 class="title page-header">{{ $t("lang.UserParameters.roleTemplate") }}</h4>
  32. <div class="role-templates">
  33. <li v-for="template in loginUserDto.roleTemplates" :key="template.no">{{ template.name }}</li>
  34. </div>
  35. </div>
  36. </div>
  37. <div
  38. class="row m-row"
  39. >
  40. <div class="col-md-12">
  41. <h4 class="title page-header">{{ $t("lang.UserParameters.role") }}</h4>
  42. <div class="role-templates">
  43. <li v-for="role in loginUserDto.roles" :key="role.id">{{ role.name }}</li>
  44. </div>
  45. </div>
  46. </div>
  47. <div class="row m-row">
  48. <div class="col-md-12">
  49. <h4 class="title page-header">{{ $t("lang.UserParameters.userPasswordModification") }}</h4>
  50. <div>
  51. <div class="form-group">
  52. <label class="control-label" for="oldPassword">{{ $t("lang.UserParameters.originalPassword") }}:</label>
  53. <input
  54. id="oldPassword"
  55. v-model="oldPassword"
  56. autocomplete="off"
  57. class="form-control"
  58. type="password"
  59. :placeholder="$t('lang.UserParameters.inputOriginalPassword')"
  60. />
  61. </div>
  62. <div class="form-group" :class="{'has-error has-feedback': (newPasswordCheckResult.length > 0)}">
  63. <label class="control-label" for="newPassword">{{ $t("lang.UserParameters.newPassword") }}:</label>
  64. <input
  65. id="newPassword"
  66. v-model="newPassword"
  67. autocomplete="off"
  68. class="form-control"
  69. type="password"
  70. :placeholder="$t('lang.UserParameters.inputNewPassword')"
  71. @input="handlerPasswordStrength1"
  72. />
  73. <span
  74. v-if="newPasswordCheckResult.length > 0" class="glyphicon glyphicon-remove form-control-feedback"
  75. aria-hidden="true"
  76. />
  77. <span
  78. v-if="newPasswordCheckResult.length > 0" class="control-label"
  79. for="newPassword"
  80. >{{ newPasswordCheckResult }}</span>
  81. </div>
  82. <div class="form-group" :class="{'has-error has-feedback': (newPassword2CheckResult.length > 0)}">
  83. <label class="control-label" for="newPassword2">{{ $t("lang.UserParameters.confirmPassword") }}:</label>
  84. <input
  85. id="newPassword2"
  86. v-model="newPassword2"
  87. autocomplete="off"
  88. class="form-control"
  89. type="password"
  90. :placeholder="$t('lang.UserParameters.againInputNewPassword')"
  91. @input="handlerPasswordStrength2"
  92. />
  93. <span
  94. v-if="newPassword2CheckResult.length > 0" class="glyphicon glyphicon-remove form-control-feedback"
  95. aria-hidden="true"
  96. />
  97. <span
  98. v-if="newPassword2CheckResult.length > 0" class="control-label"
  99. for="newPassword"
  100. >{{ newPassword2CheckResult }}</span>
  101. </div>
  102. </div>
  103. </div>
  104. </div>
  105. <!-- <div
  106. v-if="isShowUserParamter"
  107. class="row m-row"
  108. >
  109. <div class="col-md-12">
  110. <h4 class="title page-header">用户参数设置</h4>
  111. <div v-if="isShowUserParamter">
  112. <div
  113. v-for="item in parameterValues"
  114. :key="item.id"
  115. class="form-group"
  116. >
  117. <label>{{ item.displayName }}</label>
  118. <input
  119. v-if="item.displayType == 'CheckBoxEditor'"
  120. v-model="item.value"
  121. autocomplete="off"
  122. type="checkbox"
  123. />
  124. <input
  125. v-else
  126. v-model="item.value"
  127. autocomplete="off"
  128. type="text"
  129. class="form-control"
  130. />
  131. </div>
  132. </div>
  133. </div>
  134. </div> -->
  135. <div class="row m-row">
  136. <div class="col-md-12">
  137. <button
  138. type="button"
  139. class="btn btn-success"
  140. @click="saveUserParamter"
  141. >
  142. {{ $t("lang.UserParameters.save") }}
  143. </button>
  144. <button
  145. type="button"
  146. class="btn btn-danger"
  147. @click="clear"
  148. >
  149. {{ $t("lang.UserParameters.clearUserSettings") }}
  150. </button>
  151. </div>
  152. </div>
  153. </div>
  154. </div>
  155. </template>
  156. <script>
  157. import Common from '../common/Common.js';
  158. import UserStorageResource from '../api/base/UserStorageResource.js';
  159. import UserResourceV2 from '../api/base/UserResourceV2.js';
  160. import UserResource from '../api/base/UserResource.js';
  161. import AuthSettingResource from '../api/commom/AuthSettingResource.js';
  162. import ImageUpload from '../widget/image-upload.vue';
  163. import {requestFailed, requestSuccess} from '../common/request-result.js';
  164. import {notificationSuccess} from '../common/notification.js';
  165. import PasswordService from '../common/PasswordService.js';
  166. import {Notify, Uuid} from 'pc-component-v3';
  167. import store from '../store/index.js';
  168. export default {
  169. components: {
  170. ImageUpload,
  171. },
  172. data: function () {
  173. return {
  174. oldPassword: '',
  175. newPassword: '',
  176. newPasswordCheckResult: '',
  177. newPassword2: '',
  178. newPassword2CheckResult: '',
  179. parameterValues: [],
  180. isShowUserParamter: false,
  181. loginInfo: null,
  182. loginUserDto: '',
  183. };
  184. },
  185. mounted: function () {
  186. // this.getParameterValue();
  187. this.getLoginInfo();
  188. },
  189. methods: {
  190. /**
  191. * 获取用户参数
  192. */
  193. getParameterValue: function () {
  194. var _self = this;
  195. $.ajax({
  196. url: Common.getApiURL('userParamResource/query'),
  197. dataType: 'json',
  198. type: 'post',
  199. beforeSend: function (request) {
  200. Common.addTokenToRequest(request);
  201. },
  202. success: function (data) {
  203. _self.showParameterValue(data);
  204. },
  205. error: function (XMLHttpRequest, textStatus, errorThrown) {
  206. Common.processException(
  207. XMLHttpRequest,
  208. textStatus,
  209. errorThrown,
  210. );
  211. },
  212. });
  213. },
  214. /**
  215. * 渲染用户参数
  216. */
  217. showParameterValue: function (data) {
  218. var _self = this;
  219. // 清空数据
  220. _self.parameterValues.splice(0, _self.parameterValues.length);
  221. // 修复用户头像不显示的BUG
  222. _self.isShowUserParamter = true;
  223. if (data == undefined || data.length == 0) {
  224. return;
  225. }
  226. for (var i = 0, len = data.length; i < len; i++) {
  227. _self.parameterValues.push(data[i]);
  228. if (data[i].displayType == 'CheckBoxEditor') {
  229. if (data[i].value == 'true') {
  230. data[i].value = true;
  231. } else {
  232. data[i].value = false;
  233. }
  234. }
  235. }
  236. },
  237. /**
  238. * 保存用户参数
  239. */
  240. saveUserParamter: function () {
  241. var _self = this;
  242. var id;
  243. var value;
  244. var userParams = [];
  245. for (var i = 0, len = _self.parameterValues.length; i < len; i++) {
  246. id = _self.parameterValues[i].id;
  247. if (_self.parameterValues[i].displayType == 'CheckBoxEditor') {
  248. value =
  249. _self.parameterValues[i].value == true
  250. ? 'true'
  251. : 'false';
  252. } else {
  253. value = _self.parameterValues[i].value;
  254. }
  255. var aa = {
  256. id: id,
  257. value: value,
  258. };
  259. userParams.push(aa);
  260. }
  261. console.log(userParams);
  262. $.ajax({
  263. url: Common.getApiURL('userParamResource/update'),
  264. dataType: 'json',
  265. type: 'post',
  266. contentType: 'application/json; charset=utf-8',
  267. data: JSON.stringify(userParams),
  268. beforeSend: function (request) {
  269. Common.addTokenToRequest(request);
  270. },
  271. success: function (data) {
  272. _self.getParameterValue();
  273. },
  274. });
  275. // 修改密码
  276. var oldPassword = _self.oldPassword;
  277. var newPassword = _self.newPassword;
  278. var newPassword2 = _self.newPassword2;
  279. if (oldPassword != null && oldPassword != '') {
  280. if (newPassword == '') {
  281. Notify.error('错误', '新密码不能为空', false);
  282. return;
  283. }
  284. if (newPassword.indexOf(' ') > -1) {
  285. Notify.error('错误', '新密码中不允许包含空格字符', false);
  286. return;
  287. }
  288. if (newPassword != newPassword2) {
  289. Notify.error('错误',
  290. '确认密码与新密码不一致,请核对后再提交',
  291. false,
  292. );
  293. return;
  294. }
  295. if (oldPassword == newPassword) {
  296. Notify.error('错误', '新密码与原密码一致', false);
  297. return;
  298. }
  299. let message = PasswordService.handlerPasswordStrength(this.$i18n.locale, newPassword);
  300. if (message != null && message.length > 0) {
  301. Notify.error('警告', message, false);
  302. return;
  303. }
  304. $.ajax({
  305. url: Common.getApiURL('userResource/updateUserPassword'),
  306. async: false,
  307. type: 'post',
  308. dataType: 'text',
  309. data: {
  310. oldPassword: oldPassword,
  311. newPassword: newPassword,
  312. newPassword2: newPassword2,
  313. },
  314. beforeSend: function (request) {
  315. Common.addTokenToRequest(request);
  316. },
  317. success: function (data) {
  318. if (data != null && data != '') {
  319. Notify.success('操作成功', data, 1500);
  320. _self.oldPassword = '';
  321. _self.newPassword = '';
  322. _self.newPassword2 = '';
  323. _self.getParameterValue();
  324. }
  325. },
  326. error: function (XMLHttpRequest, textStatus, errorThrown) {
  327. Common.processException(
  328. XMLHttpRequest,
  329. textStatus,
  330. errorThrown,
  331. );
  332. },
  333. });
  334. } else if (
  335. (newPassword == null && newPassword == '') ||
  336. (newPassword2 == null && newPassword2 == '')
  337. ) {
  338. Notify.error('错误', '请填写完整再提交', false);
  339. return;
  340. }
  341. },
  342. /**
  343. * 上传用户的图片
  344. */
  345. uploadUserImage: function () {
  346. UserResource.updateImageName(this.loginUserDto.id, this.loginUserDto.imageName).then(successData => {
  347. if (successData.errorCode !== 0) {
  348. requestFailed(successData);
  349. } else {
  350. let data = JSON.parse(localStorage.getItem('#LoginInfo'));
  351. const newData = {...data,userImageUrl:this.loginUserDto.imageName};
  352. localStorage.setItem('#LoginInfo',JSON.stringify(newData));
  353. this.$store.commit('updateImageSrc', this.loginUserDto.imageName);
  354. notificationSuccess('用户图片上传成功', '操作成功');
  355. }
  356. }, errorData => {
  357. Common.processException(errorData);
  358. });
  359. },
  360. /**
  361. * 清空用户自定义设置
  362. */
  363. clear: function () {
  364. UserStorageResource.clearUserStorage().then(successData => {
  365. Notify.success('成功', '用户自定义设置删除成功', 1500);
  366. }, errorData => {
  367. Common.processException(errorData);
  368. });
  369. },
  370. /**
  371. * 获取loginInfo
  372. * @return {void}
  373. */
  374. getLoginInfo: function () {
  375. var _self = this;
  376. var json = localStorage.getItem('#LoginInfo');
  377. this.loginInfo = JSON.parse(json);
  378. let userId = this.loginInfo.userId;
  379. // add here
  380. UserResourceV2.uniqueById(userId).then(successData => {
  381. if (successData.errorCode === 0) {
  382. _self.loginUserDto = successData.data;
  383. } else {
  384. requestSuccess(successData);
  385. }
  386. }, errorData => {
  387. Common.processException(errorData);
  388. });
  389. },
  390. handlerPasswordStrength1: function () {
  391. if (this.newPassword == null || this.newPassword.length == 0) {
  392. this.newPasswordCheckResult = '';
  393. return;
  394. }
  395. let message = PasswordService.handlerPasswordStrength(this.$i18n.locale, this.newPassword);
  396. if (message != null && message.length > 0) {
  397. this.newPasswordCheckResult = message;
  398. } else {
  399. this.newPasswordCheckResult = '';
  400. }
  401. },
  402. handlerPasswordStrength2: function () {
  403. if (this.newPassword2 == null || this.newPassword2.length2 == 0) {
  404. this.newPassword2CheckResult = '';
  405. return;
  406. }
  407. if (this.newPassword != this.newPassword2) {
  408. this.newPassword2CheckResult = '两次密码输入不一致!';
  409. } else {
  410. this.newPassword2CheckResult = '';
  411. }
  412. },
  413. },
  414. };
  415. </script>
  416. <style scoped>
  417. .title {
  418. margin: 0px 0px 10px 0px;
  419. }
  420. .title-addon {
  421. font-size: large;
  422. margin-left: 20px;
  423. }
  424. .divClass {
  425. text-align: center;
  426. font-size: 30px;
  427. color: red;
  428. }
  429. .role-templates {
  430. display: flex;
  431. flex-wrap: wrap;
  432. gap: 10px; /* 设置间隔 */
  433. }
  434. </style>