From 2e7dbd705fc82e8db74b073e55af938d67d8c19f Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期二, 17 三月 2026 09:05:49 +0800
Subject: [PATCH] #

---
 src/main/webapp/static/js/user/user.js |  610 +++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 389 insertions(+), 221 deletions(-)

diff --git a/src/main/webapp/static/js/user/user.js b/src/main/webapp/static/js/user/user.js
index 0e06c7e..07b1c31 100644
--- a/src/main/webapp/static/js/user/user.js
+++ b/src/main/webapp/static/js/user/user.js
@@ -1,238 +1,406 @@
-var pageCurr;
-var tableData;
-var insTb2;
-layui.config({
-    base: baseUrl + "/static/layui/lay/modules/"
-}).use(['table','laydate', 'form', 'util', 'admin'], function(){
-    var table = layui.table;
-    var $ = layui.jquery;
-    var layer = layui.layer;
-    var layDate = layui.laydate;
-    var form = layui.form;
-    var admin = layui.admin;
-    var util = layui.util;
-
-    insTb2 = table.render({
-        elem: '#userTable',
-        headers: {token: localStorage.getItem('token')},
-        url: baseUrl+'/user/list/auth',
-        page: true,
-        limit: 15,
-        limits: [15, 30, 50, 100, 200, 500],
-        toolbar: '#userToolbar',
-        height: 'full-100',
-        cols: [[
-            {type: 'checkbox'}
-            // ,{field: 'hostName', align: 'center',title: '鎺堟潈鍟嗘埛', templet: '#hostTpl', width: 140}
-            // ,{field: 'nickname', align: 'center',title: '鐢ㄦ埛鍚�'}
-            ,{field: 'username', align: 'center',title: '鐧诲綍璐︽埛'}
-            ,{field: 'mobile', align: 'center',title: '鎵嬫満鍙�'}
-            // ,{field: 'deptName', align: 'center',title: '鎵�灞為儴闂�'}
-            ,{field: 'roleName', align: 'center',title: '瑙掕壊'}
-            ,{field: 'email', align: 'center',title: '閭'}
-            // ,{field: 'sex$', align: 'center',title: '鎬у埆'}
-            ,{field: 'createTime$', align: 'center',title: '娉ㄥ唽鏃堕棿', hide: true}
-            ,{field: 'status$', align: 'center',title: '鐘舵��', templet: '#statusTpl', width: 120, unresize: true}
-
-            ,{fixed: 'right', title:'鎿嶄綔', align: 'center', toolbar: '#operate', width:170}
-        ]],
-        request: {
-            pageName: 'curr',
-            pageSize: 'limit'
-        },
-        parseData: function (res) {
-            return {
-                'code': res.code,
-                'msg': res.msg,
-                'count': res.data.total,
-                'data': res.data.records
-            }
-        },
-        response: {
-            statusCode: 200
-        },
-        done: function(res, curr, count) {
-            if (res.code === 403) {
-                top.location.href = baseUrl+"/";
-            }
-            tableData = table.cache.userTable;
-            pageCurr=curr;
-            limit();
+(function () {
+    function handleForbidden(res) {
+        if (res && Number(res.code) === 403) {
+            top.location.href = baseUrl + "/";
+            return true;
         }
-    });
-    /* 琛ㄦ牸2鎼滅储 */
-    form.on('submit(userTbSearch)', function (data) {
-        insTb2.reload({where: data.field, page: {curr: 1}});
         return false;
-    });
+    }
 
-    /* 琛ㄦ牸2澶村伐鍏锋爮鐐瑰嚮浜嬩欢 */
-    table.on('toolbar(userTable)', function (obj) {
-        var checkStatus = table.checkStatus(obj.config.id).data;
-        if (obj.event === 'add') { // 娣诲姞
-            showEditModel()
-        } else if (obj.event === 'del') { // 鍒犻櫎
-            if (checkStatus.length === 0) {
-                layer.msg('璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁', {icon: 2});
-                return;
-            }
-            del(checkStatus.map(function (d) {
-                return d.id;
-            }));
-        }
-    });
-
-    // 淇敼鐘舵��
-    form.on('switch(statusSwitch)', function (obj) {
-        var index  = obj.othis.parents('tr').attr("data-index");
-        var data = tableData[index];
-        data[this.name] = obj.elem.checked?1:0;
-        http.post(baseUrl+"/user/edit/auth", {id: data.id, status: data[this.name]}, function (res) {
-            layer.msg(res.msg, {icon: 1});
-        })
-    })
-
-    /* 琛ㄦ牸2宸ュ叿鏉$偣鍑讳簨浠� */
-    table.on('tool(userTable)', function (obj) {
-        var data = obj.data;
-        switch (obj.event) {
-            // 缂栬緫
-            case 'edit':
-                showEditModel(data)
-                break;
-            // 鍒犻櫎
-            case 'del':
-                del([data.id]);
-                break;
-            // 閲嶇疆瀵嗙爜
-            case 'resetPwd':
-                admin.open({
-                    type: 1,
-                    title: '閲嶇疆瀵嗙爜',
-                    offset: '150px',
-                    area: ['360px'],
-                    shade: 0.1,
-                    shadeClose: true,
-                    content: $("#resetpwd-window").html(),
-                    success: function(layero, index){
-                        layer.iframeAuto(index);
-                        $('#resetUserId').val(data.id);
+    new Vue({
+        el: "#app",
+        data: function () {
+            return {
+                loading: false,
+                dialogSubmitting: false,
+                resetSubmitting: false,
+                searchForm: {
+                    username: "",
+                    mobile: ""
+                },
+                tableData: [],
+                selection: [],
+                roles: [],
+                page: {
+                    curr: 1,
+                    limit: 15,
+                    total: 0
+                },
+                dialog: {
+                    visible: false,
+                    mode: "create"
+                },
+                dialogForm: {
+                    id: null,
+                    username: "",
+                    mobile: "",
+                    password: "",
+                    roleId: null,
+                    status: 1,
+                    mfaAllow: 0
+                },
+                resetDialog: {
+                    visible: false,
+                    userId: null,
+                    username: "",
+                    password: ""
+                },
+                dialogRules: {
+                    username: [
+                        { required: true, message: "璇疯緭鍏ョ櫥褰曡处鎴�", trigger: "blur" }
+                    ],
+                    mobile: [
+                        { required: true, message: "璇疯緭鍏ヨ处鍙�", trigger: "blur" }
+                    ],
+                    roleId: [
+                        { required: true, message: "璇烽�夋嫨瑙掕壊", trigger: "change" }
+                    ],
+                    password: [
+                        {
+                            validator: function (rule, value, callback) {
+                                if (this.dialog.mode !== "create") {
+                                    callback();
+                                    return;
+                                }
+                                if (!value) {
+                                    callback(new Error("璇疯緭鍏ュ垵濮嬪瘑鐮�"));
+                                    return;
+                                }
+                                if (String(value).length < 4) {
+                                    callback(new Error("鍒濆瀵嗙爜涓嶈兘灏戜簬4浣�"));
+                                    return;
+                                }
+                                callback();
+                            }.bind(this),
+                            trigger: "blur"
+                        }
+                    ]
+                },
+                resetRules: {
+                    password: [
+                        { required: true, message: "璇疯緭鍏ユ柊瀵嗙爜", trigger: "blur" },
+                        {
+                            validator: function (rule, value, callback) {
+                                if (String(value || "").length < 4) {
+                                    callback(new Error("鏂板瘑鐮佷笉鑳藉皯浜�4浣�"));
+                                    return;
+                                }
+                                callback();
+                            },
+                            trigger: "blur"
+                        }
+                    ]
+                }
+            };
+        },
+        created: function () {
+            this.loadRoles();
+            this.loadTable();
+        },
+        methods: {
+            authHeaders: function () {
+                return { token: localStorage.getItem("token") };
+            },
+            loadRoles: function () {
+                var vm = this;
+                $.ajax({
+                    url: baseUrl + "/role/list/auth",
+                    method: "GET",
+                    headers: vm.authHeaders(),
+                    data: {
+                        curr: 1,
+                        limit: 500
+                    },
+                    success: function (res) {
+                        if (handleForbidden(res)) {
+                            return;
+                        }
+                        if (Number(res.code) !== 200) {
+                            vm.$message.error(res.msg || "瑙掕壊鍔犺浇澶辫触");
+                            return;
+                        }
+                        var payload = res.data || {};
+                        vm.roles = Array.isArray(payload.records) ? payload.records : [];
+                    },
+                    error: function () {
+                        vm.$message.error("瑙掕壊鍔犺浇澶辫触");
                     }
                 });
-                break;
-        }
-    });
-
-    /* 鏄剧ず琛ㄥ崟寮圭獥 */
-    function showEditModel(mData) {
-        admin.open({
-            type: 1,
-            area: '600px',
-            title: (mData ? '淇敼' : '娣诲姞') + '鐢ㄦ埛',
-            content: $('#editDialog').html(),
-            success: function (layero, dIndex) {
-                // 鍥炴樉琛ㄥ崟鏁版嵁
-                form.val('detail', mData);
-                // 琛ㄥ崟鎻愪氦浜嬩欢
-                form.on('submit(editSubmit)', function (data) {
-                    if (isEmpty(data.field.roleId)) {
-                        layer.msg('璇烽�夋嫨瑙掕壊', {icon: 2});
+            },
+            loadTable: function () {
+                var vm = this;
+                vm.loading = true;
+                $.ajax({
+                    url: baseUrl + "/user/list/auth",
+                    method: "GET",
+                    headers: vm.authHeaders(),
+                    data: {
+                        curr: vm.page.curr,
+                        limit: vm.page.limit,
+                        username: vm.searchForm.username,
+                        mobile: vm.searchForm.mobile
+                    },
+                    success: function (res) {
+                        if (handleForbidden(res)) {
+                            return;
+                        }
+                        if (Number(res.code) !== 200) {
+                            vm.$message.error(res.msg || "鍔犺浇澶辫触");
+                            return;
+                        }
+                        var payload = res.data || {};
+                        vm.tableData = Array.isArray(payload.records) ? payload.records : [];
+                        vm.page.total = Number(payload.total || 0);
+                    },
+                    error: function () {
+                        vm.$message.error("鍔犺浇澶辫触");
+                    },
+                    complete: function () {
+                        vm.loading = false;
+                    }
+                });
+            },
+            handleSearch: function () {
+                this.page.curr = 1;
+                this.loadTable();
+            },
+            handleResetSearch: function () {
+                this.searchForm = {
+                    username: "",
+                    mobile: ""
+                };
+                this.page.curr = 1;
+                this.loadTable();
+            },
+            handleSelectionChange: function (rows) {
+                this.selection = rows || [];
+            },
+            handleCurrentChange: function (curr) {
+                this.page.curr = curr;
+                this.loadTable();
+            },
+            handleSizeChange: function (limit) {
+                this.page.limit = limit;
+                this.page.curr = 1;
+                this.loadTable();
+            },
+            openCreateDialog: function () {
+                this.dialog.mode = "create";
+                this.dialog.visible = true;
+                this.dialogForm = {
+                    id: null,
+                    username: "",
+                    mobile: "",
+                    password: "",
+                    roleId: null,
+                    status: 1,
+                    mfaAllow: 0
+                };
+                this.clearDialogValidate();
+            },
+            openEditDialog: function (row) {
+                this.dialog.mode = "edit";
+                this.dialog.visible = true;
+                this.dialogForm = {
+                    id: row.id,
+                    username: row.username || "",
+                    mobile: row.mobile || "",
+                    password: "",
+                    roleId: row.roleId == null ? null : Number(row.roleId),
+                    status: row.status == null ? 1 : Number(row.status),
+                    mfaAllow: row.mfaAllow == null ? 0 : Number(row.mfaAllow)
+                };
+                this.clearDialogValidate();
+            },
+            clearDialogValidate: function () {
+                var vm = this;
+                vm.$nextTick(function () {
+                    if (vm.$refs.dialogForm) {
+                        vm.$refs.dialogForm.clearValidate();
+                    }
+                });
+            },
+            closeDialog: function () {
+                this.dialog.visible = false;
+            },
+            submitDialog: function () {
+                var vm = this;
+                if (!vm.$refs.dialogForm) {
+                    return;
+                }
+                vm.$refs.dialogForm.validate(function (valid) {
+                    if (!valid) {
                         return false;
                     }
-                    var loadIndex = layer.load(2);
+                    vm.dialogSubmitting = true;
                     $.ajax({
-                        url: baseUrl+"/user/"+(mData?'update':'add')+"/auth",
-                        headers: {'token': localStorage.getItem('token')},
-                        data: data.field,
-                        method: 'POST',
+                        url: baseUrl + "/user/" + (vm.dialog.mode === "create" ? "add" : "update") + "/auth",
+                        method: "POST",
+                        headers: vm.authHeaders(),
+                        data: vm.buildDialogPayload(),
                         success: function (res) {
-                            layer.close(loadIndex);
-                            if (res.code === 200){
-                                layer.close(dIndex);
-                                layer.msg(res.msg, {icon: 1});
-                                $(".layui-laypage-btn")[0].click();
-                            } else if (res.code === 403){
-                                top.location.href = baseUrl+"/";
-                            }else {
-                                layer.msg(res.msg, {icon: 2});
+                            if (handleForbidden(res)) {
+                                return;
                             }
+                            if (Number(res.code) !== 200) {
+                                vm.$message.error(res.msg || "淇濆瓨澶辫触");
+                                return;
+                            }
+                            vm.$message.success(res.msg || "淇濆瓨鎴愬姛");
+                            vm.dialog.visible = false;
+                            vm.loadTable();
+                        },
+                        error: function () {
+                            vm.$message.error("淇濆瓨澶辫触");
+                        },
+                        complete: function () {
+                            vm.dialogSubmitting = false;
                         }
-                    })
-                    return false;
+                    });
+                    return true;
                 });
-                // 寮圭獥涓嶅嚭鐜版粴鍔ㄦ潯
-                $(layero).children('.layui-layer-content').css('overflow', 'visible');
-                layui.form.render('select');
-            }
-        });
-    }
-
-
-    /* 鍒犻櫎璁㈠崟 */
-    function del(ids) {
-        layer.confirm('纭畾瑕佸垹闄ら�変腑鏁版嵁鍚楋紵', {
-            skin: 'layui-layer-admin',
-            shade: .1
-        }, function (i) {
-            layer.close(i);
-            var loadIndex = layer.load(2);
-            $.ajax({
-                url: baseUrl+"/user/delete/auth",
-                headers: {'token': localStorage.getItem('token')},
-                data: {ids: ids},
-                method: 'POST',
-                success: function (res) {
-                    layer.close(loadIndex);
-                    if (res.code === 200){
-                        layer.msg(res.msg, {icon: 1});
-                        $(".layui-laypage-btn")[0].click();
-                    } else if (res.code === 403){
-                        top.location.href = baseUrl+"/";
-                    }else {
-                        layer.msg(res.msg, {icon: 2});
-                    }
-                }
-            })
-
-        });
-    }
-
-    // 閲嶇疆瀵嗙爜
-    form.on('submit(savePwd)', function (data) {
-        $.ajax({
-            url: baseUrl+"/user/update/auth",
-            headers: {'token': localStorage.getItem('token')},
-            data: {
-                id: data.field.resetUserId,
-                password: hex_md5(data.field.resetPassword)
             },
-            method: 'POST',
-            success: function (res) {
-                if (res.code === 200){
-                    layer.closeAll();
-                    layer.msg("閲嶇疆瀵嗙爜鎴愬姛", {icon: 1});
-                } else if (res.code === 403){
-                    top.location.href = baseUrl+"/";
-                }else {
-                    layer.msg(res.msg, {icon: 2})
+            buildDialogPayload: function () {
+                var payload = {
+                    username: this.dialogForm.username,
+                    mobile: this.dialogForm.mobile,
+                    roleId: this.dialogForm.roleId,
+                    status: this.dialogForm.status,
+                    mfaAllow: this.dialogForm.mfaAllow
+                };
+                if (this.dialog.mode === "edit") {
+                    payload.id = this.dialogForm.id;
+                } else {
+                    payload.password = hex_md5(this.dialogForm.password);
                 }
+                return payload;
+            },
+            openResetPasswordDialog: function (row) {
+                this.resetDialog = {
+                    visible: true,
+                    userId: row.id,
+                    username: row.username || "",
+                    password: ""
+                };
+                var vm = this;
+                vm.$nextTick(function () {
+                    if (vm.$refs.resetForm) {
+                        vm.$refs.resetForm.clearValidate();
+                    }
+                });
+            },
+            closeResetDialog: function () {
+                this.resetDialog.visible = false;
+            },
+            submitResetPassword: function () {
+                var vm = this;
+                if (!vm.$refs.resetForm) {
+                    return;
+                }
+                vm.$refs.resetForm.validate(function (valid) {
+                    if (!valid) {
+                        return false;
+                    }
+                    vm.resetSubmitting = true;
+                    $.ajax({
+                        url: baseUrl + "/user/resetPassword/auth",
+                        method: "POST",
+                        headers: vm.authHeaders(),
+                        data: {
+                            id: vm.resetDialog.userId,
+                            password: hex_md5(vm.resetDialog.password)
+                        },
+                        success: function (res) {
+                            if (handleForbidden(res)) {
+                                return;
+                            }
+                            if (Number(res.code) !== 200) {
+                                vm.$message.error(res.msg || "閲嶇疆瀵嗙爜澶辫触");
+                                return;
+                            }
+                            vm.$message.success("閲嶇疆瀵嗙爜鎴愬姛");
+                            vm.resetDialog.visible = false;
+                        },
+                        error: function () {
+                            vm.$message.error("閲嶇疆瀵嗙爜澶辫触");
+                        },
+                        complete: function () {
+                            vm.resetSubmitting = false;
+                        }
+                    });
+                    return true;
+                });
+            },
+            toggleStatus: function (row) {
+                var vm = this;
+                var currentStatus = Number(row.status) === 1 ? 1 : 0;
+                $.ajax({
+                    url: baseUrl + "/user/edit/auth",
+                    method: "POST",
+                    headers: vm.authHeaders(),
+                    data: {
+                        id: row.id,
+                        status: currentStatus
+                    },
+                    success: function (res) {
+                        if (handleForbidden(res)) {
+                            return;
+                        }
+                        if (Number(res.code) !== 200) {
+                            row.status = currentStatus === 1 ? 0 : 1;
+                            vm.$message.error(res.msg || "鐘舵�佹洿鏂板け璐�");
+                            return;
+                        }
+                        row.status$ = currentStatus === 1 ? "姝e父" : "绂佺敤";
+                        vm.$message.success("鐘舵�佸凡鏇存柊");
+                    },
+                    error: function () {
+                        row.status = currentStatus === 1 ? 0 : 1;
+                        vm.$message.error("鐘舵�佹洿鏂板け璐�");
+                    }
+                });
+            },
+            removeSelection: function () {
+                var ids = this.selection.map(function (item) {
+                    return item.id;
+                });
+                this.removeRows(ids);
+            },
+            removeRows: function (ids) {
+                var vm = this;
+                if (!ids || ids.length === 0) {
+                    vm.$message.warning("璇烽�夋嫨瑕佸垹闄ょ殑鏁版嵁");
+                    return;
+                }
+                vm.$confirm("纭畾鍒犻櫎閫変腑鐨勮褰曞悧锛�", "鎻愮ず", {
+                    type: "warning",
+                    confirmButtonText: "纭畾",
+                    cancelButtonText: "鍙栨秷"
+                }).then(function () {
+                    $.ajax({
+                        url: baseUrl + "/user/delete/auth",
+                        method: "POST",
+                        headers: vm.authHeaders(),
+                        traditional: true,
+                        data: { "ids[]": ids },
+                        success: function (res) {
+                            if (handleForbidden(res)) {
+                                return;
+                            }
+                            if (Number(res.code) !== 200) {
+                                vm.$message.error(res.msg || "鍒犻櫎澶辫触");
+                                return;
+                            }
+                            vm.$message.success("鍒犻櫎鎴愬姛");
+                            vm.loadTable();
+                        },
+                        error: function () {
+                            vm.$message.error("鍒犻櫎澶辫触");
+                        }
+                    });
+                }).catch(function () {
+                });
             }
-        })
-        return false;
-    })
-
-});
-
-function tableReload(child) {
-    var searchData = {};
-    $.each($('#search-box [name]').serializeArray(), function() {
-        searchData[this.name] = this.value;
-    });
-    (child ? parent.tableIns : tableIns).reload({
-        where: searchData,
-        page: {
-            curr: pageCurr
         }
     });
-}
-
+})();

--
Gitblit v1.9.1