userManage.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. var _this, dataObj=[], _Tok = null;
  2. new Vue({
  3. el: '#app',
  4. data: function() {
  5. return {
  6. parentName: {
  7. deptName: "请选择",
  8. deptId: null
  9. },
  10. defaultProps: {
  11. children: 'children',
  12. label: 'label'
  13. },
  14. tableData: [],
  15. nowForm:{
  16. postIds: [],
  17. roleIds: []
  18. },
  19. dialogVisible:false,
  20. inpKey:"",
  21. sexOptions:[],
  22. postOptions:[],
  23. deptOptions :[],
  24. roleOptions:[],
  25. readonlyInput: true,
  26. pwdDialog:false,
  27. pwdInfo:{
  28. userId:null,
  29. newPwd:"",
  30. pwdName:null
  31. },
  32. loading: false,
  33. curPage: 1,
  34. allTotal: 0,
  35. }
  36. },
  37. created() {
  38. _this = this;
  39. _Tok = getCookie("Admin-Token") != "null" && getCookie("Admin-Token") != null ? getCookie("Admin-Token") : "";
  40. _this.reSet();
  41. _this.getList();
  42. _this.getSex();
  43. _this.getTree();
  44. },
  45. methods: {
  46. cancelReadOnly() {
  47. _this.readonlyInput= false;
  48. },
  49. getList() {
  50. _this.loading = true;
  51. let data1 = {
  52. pageNum:_this.curPage,
  53. pageSize:20
  54. };
  55. let _opts = {
  56. url: baseUrl + "/system/user/list",
  57. type:"GET"
  58. };
  59. let _head = {
  60. "Authorization":"Bearer "+_Tok
  61. };
  62. getAxios(_opts, data1, _head)
  63. .then(function(res) {
  64. if (res.code == 200) {
  65. _this.tableData = res.rows;
  66. _this.allTotal = res.total;
  67. dataObj = res.rows;
  68. }else{
  69. _this.$message.error(res.msg);
  70. }
  71. _this.loading = false;
  72. })
  73. },
  74. handleCurrentChange(val) {
  75. if(val != _this.curPage){
  76. _this.curPage = val;
  77. _this.getList();
  78. }
  79. },
  80. getSex(){
  81. let data1 = {};
  82. let _head = {
  83. "Authorization":"Bearer "+_Tok
  84. };
  85. let _opts = {
  86. url: baseUrl + "/system/dict/data/type/sys_user_sex",
  87. type:"GET"
  88. };
  89. getAxios(_opts, data1,_head)
  90. .then(function(res) {
  91. if (res.code == 200) {
  92. _this.sexOptions = res.data;
  93. }
  94. })
  95. },
  96. getTree(){
  97. let data1 = {};
  98. let _opts = {
  99. url: baseUrl + "/system/dept/treeselect",
  100. type:"GET"
  101. };
  102. let _head = {
  103. "Authorization":"Bearer "+_Tok
  104. };
  105. getAxios(_opts, data1,_head)
  106. .then(function(res) {
  107. if (res.code == 200) {
  108. _this.deptOptions = res.data;
  109. }
  110. })
  111. },
  112. Search(_key){
  113. let newArr = [],_ovj = dataObj;
  114. if(_key == ""){
  115. newArr = dataObj;
  116. }else{
  117. for(var i=0;i<_ovj.length;i++){
  118. if( JSON.stringify(_ovj[i]).indexOf(_key) != -1){
  119. newArr.push(_ovj[i])
  120. }
  121. }
  122. }
  123. _this.tableData = newArr;
  124. },
  125. reSet() {
  126. _this.nowForm = {
  127. deptId: 0,
  128. userName: "",
  129. nickName: "",
  130. password: "",
  131. phonenumber: "",
  132. email: "",
  133. sex: "2",
  134. status: "0",
  135. remark: "",
  136. postIds: [],
  137. roleIds: [],
  138. userId: null
  139. };
  140. },
  141. newAdd(){
  142. let data1 = {};
  143. let _opts = {
  144. url: baseUrl + "/system/user/",
  145. type:"GET"
  146. };
  147. let _head = {
  148. "Authorization":"Bearer "+_Tok
  149. };
  150. getAxios(_opts, data1,_head)
  151. .then(function(res) {
  152. if (res.code == 200) {
  153. _this.postOptions = res.posts;
  154. _this.roleOptions = res.roles;
  155. _this.parentName = {
  156. deptName: _this.deptOptions[0].label,
  157. deptId: _this.deptOptions[0].id
  158. };
  159. _this.reSet();
  160. _this.dialogVisible = true;
  161. }
  162. })
  163. },
  164. Edit(_row){
  165. let data1 = {};
  166. let _opts = {
  167. url: baseUrl + "/system/user/" + _row.userId,
  168. type:"GET"
  169. };
  170. let _head = {
  171. "Authorization":"Bearer "+_Tok
  172. };
  173. getAxios(_opts, data1,_head)
  174. .then(function(res) {
  175. if (res.code == 200) {
  176. _this.nowForm = res.data;
  177. if(res.data.deptId == null){
  178. _this.parentName = {
  179. deptName: _this.deptOptions[0].label,
  180. deptId: _this.deptOptions[0].id
  181. };
  182. }else{
  183. _this.parentName = res.data.dept;
  184. }
  185. _this.postOptions = res.posts;
  186. _this.roleOptions = res.roles;
  187. _this.nowForm.postIds = res.postIds;
  188. _this.nowForm.roleIds = res.roleIds;
  189. _this.dialogVisible = true;
  190. }
  191. })
  192. },
  193. Delete(_row){
  194. _this.$confirm('是否确认删除编号为"'+_row.userId+'"的数据项?', '温馨提示', {
  195. confirmButtonText: '确定',
  196. cancelButtonText: '取消',
  197. type: 'warning'
  198. }).then(() => {
  199. let data1 = {};
  200. let _opts = {
  201. url: baseUrl + "/system/user/"+_row.userId,
  202. type:"DELETE"
  203. };
  204. let _head = {
  205. "Authorization":"Bearer "+_Tok
  206. };
  207. getAxios(_opts, data1,_head)
  208. .then(function(res) {
  209. if(res.code == 200){
  210. _this.$message({
  211. type: 'success',
  212. message: '删除成功!'
  213. });
  214. _this.getList();
  215. }else{
  216. _this.$message.error(res.msg);
  217. }
  218. })
  219. }).catch(() => {
  220. });
  221. },
  222. RePwd(_row){
  223. if(_row.userId != null&&_row.userId != undefined){
  224. _this.pwdInfo.pwdName = _row.nickName;
  225. _this.pwdInfo.userId = _row.userId;
  226. _this.pwdDialog = true;
  227. }
  228. },
  229. conPwd(){
  230. if(_this.pwdInfo.newPwd == ""){
  231. _this.$message({
  232. type: 'warning',
  233. message: "请输入新密码"
  234. });
  235. return;
  236. }
  237. let data1 = JSON.stringify({
  238. password: _this.pwdInfo.newPwd,
  239. userId: _this.pwdInfo.userId
  240. });
  241. let _opts = {
  242. url:baseUrl + "/system/user/resetPwd",
  243. type: "PUT"
  244. };
  245. let _head = {
  246. "Authorization":"Bearer "+_Tok,
  247. "Content-Type": 'application/json; charset=UTF-8',
  248. };
  249. postAxios(_opts,data1,_head)
  250. .then(function(res){
  251. if(res.code == 200){
  252. _this.$message({
  253. type: 'success',
  254. message: '操作成功!'
  255. });
  256. _this.pwdDialog = false;
  257. }else{
  258. _this.$message.error(res.msg);
  259. }
  260. })
  261. },
  262. conFirm(){
  263. if(_this.nowForm.nickName == ""){
  264. _this.$message({
  265. type: 'warning',
  266. message: "请输入用户昵称"
  267. });
  268. return;
  269. }
  270. if(_this.nowForm.userName == ""&&_this.nowForm.userId == undefined){
  271. _this.$message({
  272. type: 'warning',
  273. message: "请输入用户账号"
  274. });
  275. return;
  276. }
  277. if(_this.nowForm.password == ""&&_this.nowForm.userId == undefined){
  278. _this.$message({
  279. type: 'warning',
  280. message: "请输入密码"
  281. });
  282. return;
  283. }
  284. if(!_this.nowForm.roleIds.length){
  285. _this.$message({
  286. type: 'warning',
  287. message: "请选择用户角色"
  288. });
  289. return;
  290. }
  291. if(_this.nowForm.phonenumber != ""&&_this.nowForm.phonenumber != null&&(!(/^1[3456789]\d{9}$/.test(_this.nowForm.phonenumber)))){
  292. _this.$message({
  293. type: 'warning',
  294. message: '请输入正确的手机号码',
  295. })
  296. return;
  297. }
  298. if(_this.nowForm.email != ""&&_this.nowForm.email != null&&(!(/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/.test(_this.nowForm.email)))){
  299. _this.$message({
  300. type: 'warning',
  301. message: '请输入正确的邮箱格式',
  302. })
  303. return;
  304. }
  305. _this.nowForm.deptId = _this.parentName.deptId;
  306. let data1 = JSON.stringify(_this.nowForm);
  307. let _opts = {
  308. url:baseUrl + "/system/user",
  309. type: _this.nowForm.userId == null?"POST":"PUT"
  310. };
  311. let _he = {
  312. "Authorization":"Bearer "+_Tok,
  313. "Content-Type": 'application/json; charset=UTF-8',
  314. };
  315. postAxios(_opts,data1,_he)
  316. .then(function(res){
  317. if(res.code == 200){
  318. _this.$message({
  319. type: 'success',
  320. message: '操作成功!'
  321. });
  322. _this.getList();
  323. _this.dialogVisible = false;
  324. }else{
  325. _this.$message.error(res.msg);
  326. }
  327. })
  328. },
  329. nodeClick(_e){
  330. _this.parentName = {
  331. deptName: _e.label,
  332. deptId: _e.id
  333. };
  334. this.$refs.conSelect.blur();
  335. },
  336. clearSel(_row){
  337. _this.nowForm[_row] = [];
  338. }
  339. }
  340. })