UserParameters.vue 13 KB

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