/** * 用户详情组件 * 提供用户详情查询和侧边栏显示功能 */ Vue.component('user-detail', { data() { return { // 当前查看的用户详情 currentUser: null, // 用户详情侧边栏索引 userSidebarIndex: null, // 是否正在加载 loading: false }; }, methods: { /** * 获取用户详情 * @param {number} userId 用户ID * @param {number} companyId 企业ID * @returns {Promise} 用户详情对象,获取失败则返回null */ getUserDetail: async function(companyId, userId) { if (this.loading) return null; this.loading = true; try { const loadIndex = layer.load(2, { shade: [0.3, '#0000001f'] }); const { data: res } = await axios.get('/api/web/system-web-user/get-user-info', { params: { companyId: companyId, id: userId } }); layer.close(loadIndex); if (!res.success) { this.popWarningMsg(res.msg || '获取用户详情失败'); return null; } return res.data; } catch (error) { console.error('获取用户详情失败:', error); this.popErrorMsg('获取用户详情失败,请重试'); return null; } finally { this.loading = false; } }, /** * 显示用户详情侧边栏 * @param {number} companyId 企业ID * @param {number} userId 用户ID */ showUserDetail: async function(companyId, userId) { // 先获取用户详情 const userDetail = await this.getUserDetail(companyId, userId); if (!userDetail) return; this.currentUser = userDetail; // 渲染用户详情到侧边栏 const that = this; this.userSidebarIndex = layer.open({ type: 1, title: '用户详情', area: ['400px', '100%'], offset: 'r', move: false, anim: 5, shadeClose: true, content: `
`, end: function() { // 重置组件状态 that.currentUser = null; }, success: function(layero, index) { // 设置初始样式 layero.css({ 'border-radius': '0', 'overflow': 'hidden', }); $(layero).find('.layui-layer-content').css({ 'overflow': 'hidden', }); $(layero).find('.layui-layer-title').css({ 'background-color': '#f8f8f8', 'border-bottom': '1px solid #eee' }); new Vue({ 'el': '#tl-rtc-app-user-detail', data: that.$data, methods: that.$options.methods, }) } }); }, /** * 格式化日期时间 * @param {string} dateString 日期字符串 * @returns {string} 格式化后的日期时间 */ formatDateTime: function(dateString) { if (!dateString) return '未知'; return window.util.timeAgo(dateString); }, /** * 显示企业详情 * @param {number} companyId 企业ID * @returns {void} * */ showCompanyDetail(companyId) { window.subModule.$emit('show-company-detail', companyId); } }, mounted() { window.subModule.$on('show-user-detail', this.showUserDetail); }, beforeDestroy() { window.subModule.$off('show-user-detail', this.showUserDetail); }, });