/** * 应用示例 * 使用简单HTML5前端框架实现页面交互 */ // 等待DOM加载完成 document.addEventListener('DOMContentLoaded', function() { // 初始化登录状态 initLoginStatus(); // 初始化路由 initRouter(); // 初始化计数器组件 initCounter(); }); /** * 初始化登录状态 */ function initLoginStatus() { const currentUser = localStorage.getItem('currentUser'); const welcomeMessage = document.getElementById('welcome-message'); const loginLink = document.getElementById('login-link'); const logoutLink = document.getElementById('logout-link'); if (currentUser) { const user = JSON.parse(currentUser); welcomeMessage.textContent = `欢迎,${user.emp_name} `; loginLink.style.display = 'none'; logoutLink.style.display = 'inline'; } else { welcomeMessage.textContent = ''; loginLink.style.display = 'inline'; logoutLink.style.display = 'none'; } // 登出功能 if (logoutLink) { logoutLink.addEventListener('click', function(e) { e.preventDefault(); localStorage.removeItem('currentUser'); window.location.reload(); }); } } /** * 初始化路由 */ function initRouter() { // 注册路由 Framework.router.register('home', function() { showSection('home'); }); Framework.router.register('about', function() { showSection('about'); }); Framework.router.register('counter', function() { showSection('counter'); }); Framework.router.register('models', function() { showSection('models'); initDataModels(); }); // 初始化路由 Framework.router.init(); } /** * 显示指定 section * @param {string} sectionId - section ID */ function showSection(sectionId) { // 隐藏所有 section const sections = Framework.dom.queryAll('section'); sections.forEach(section => { section.style.display = 'none'; }); // 显示指定 section const targetSection = Framework.dom.query(`#${sectionId}`); if (targetSection) { targetSection.style.display = 'block'; } } /** * 初始化计数器组件 */ function initCounter() { // 初始化状态 Framework.store.set('count', 0); // 获取DOM元素 const countElement = Framework.dom.query('#count'); const incrementButton = Framework.dom.query('#increment'); const decrementButton = Framework.dom.query('#decrement'); const resetButton = Framework.dom.query('#reset'); // 订阅状态变化 Framework.store.subscribe(function(state) { countElement.textContent = state.count; }); // 添加事件监听器 Framework.dom.on(incrementButton, 'click', function() { const currentCount = Framework.store.get('count'); Framework.store.set('count', currentCount + 1); }); Framework.dom.on(decrementButton, 'click', function() { const currentCount = Framework.store.get('count'); Framework.store.set('count', currentCount - 1); }); Framework.dom.on(resetButton, 'click', function() { Framework.store.set('count', 0); }); } // 示例:注册一个简单的组件 Framework.component.register('HelloComponent', function(props) { this.props = props; this.element = null; this.render = function() { return Framework.dom.create('div', { text: `Hello, ${this.props.name}!`, style: { padding: '20px', backgroundColor: '#f0f0f0', borderRadius: '5px', marginTop: '20px' } }); }; this.mount = function(container) { this.element = this.render(); container.appendChild(this.element); }; this.update = function(newProps) { this.props = newProps; if (this.element) { const parent = this.element.parentNode; parent.removeChild(this.element); this.element = this.render(); parent.appendChild(this.element); } }; }); // 示例:创建组件实例 // const helloComponent = Framework.component.create('HelloComponent', { name: 'World' }, document.body); /** * 初始化数据模型示例 */ function initDataModels() { // 测试审核权限模型 const auditPermissionDemo = Framework.dom.query('#audit-permission-demo'); if (auditPermissionDemo) { // 创建审核权限实例 const auditPermission = Framework.model.AuditPermission.create({ uuid: '12345678901234567890123456789012', company_id: 1, position_id: 101, audit_type: 'order', audit_level: 1, audit_scope: '*', max_audit_amount: 10000.00, sort: 1, status: 1, remark: '订单初审权限' }); // 展示审核权限数据 auditPermissionDemo.innerHTML = `
UUID: ${auditPermission.uuid}
公司ID: ${auditPermission.company_id}
岗位ID: ${auditPermission.position_id}
审核类型: ${auditPermission.audit_type}
审核层级: ${auditPermission.audit_level}
审核范围: ${auditPermission.audit_scope}
最大审核金额: ${auditPermission.max_audit_amount}
状态: ${auditPermission.status === 1 ? '正常' : '禁用'}
创建时间: ${auditPermission.create_time}
备注: ${auditPermission.remark}
UUID: ${company.uuid}
公司名称: ${company.company_name}
租户ID: ${company.tenant_id}
上级公司ID: ${company.parent_company_id}
公司简称: ${company.short_name}
所属行业: ${company.industry}
联系电话: ${company.contact_mobile}
联系邮箱: ${company.contact_email}
状态: ${getStatusText(company.status)}
创建时间: ${company.create_time}
备注: ${company.remark}
客户ID: ${customer.customer_id}
客户名称: ${customer.customer_name}
建户日期: ${customer.create_date}
最后下单日期: ${customer.last_order_date}
最后跟进日期: ${customer.last_followup_date}
跟进情况: ${customer.followup_status}
负责人: ${customer.responsible_person}
部门: ${customer.department}
协助人: ${customer.assistant}
客户地区: ${customer.region}
客户类型: ${customer.customer_type}
客户等级: ${customer.customer_level}
基本需求: ${customer.basic_requirements}
规格: ${customer.specifications}
创建时间: ${customer.created_at}
更新时间: ${customer.updated_at}
联系ID: ${customerContact.contact_id}
客户ID: ${customerContact.customer_id}
微信号: ${customerContact.wechat_id}
联系人姓名: ${customerContact.contact_name}
电话: ${customerContact.phone}
账户名称: ${customerContact.account}
账号: ${customerContact.account_number}
开户行: ${customerContact.bank}
地址: ${customerContact.address}
客户公司: ${customerContact.company_name}
创建时间: ${customerContact.created_at}
更新时间: ${customerContact.updated_at}
部门ID: ${department.id}
UUID: ${department.uuid}
公司ID: ${department.company_id}
部门名称: ${department.dept_name}
上级部门ID: ${department.parent_id}
部门级别: ${department.dept_level}
部门编码: ${department.dept_code}
部门负责人ID: ${department.leader_id}
排序号: ${department.sort}
状态: ${department.status === 1 ? '正常' : '禁用'}
创建时间: ${department.create_time}
备注: ${department.remark}
员工ID: ${employee.id}
UUID: ${employee.uuid}
公司ID: ${employee.company_id}
部门ID: ${employee.dept_id}
岗位ID: ${employee.position_id}
员工姓名: ${employee.emp_name}
手机号: ${employee.mobile}
员工工号: ${employee.emp_no}
邮箱: ${employee.email}
身份证号: ${employee.id_card}
入职时间: ${employee.entry_time}
是否公司管理员: ${employee.is_admin === 1 ? '是' : '否'}
是否部门负责人: ${employee.is_leader === 1 ? '是' : '否'}
状态: ${employee.status === 1 ? '正常' : employee.status === 2 ? '离职' : '禁用'}
最后登录时间: ${employee.last_login_time}
创建时间: ${employee.create_time}
备注: ${employee.remark}
日志ID: ${operationLog.id}
UUID: ${operationLog.uuid}
租户ID: ${operationLog.tenant_id}
操作表名: ${operationLog.table_name}
数据ID: ${operationLog.data_id}
操作类型: ${getOperTypeText(operationLog.oper_type)}
操作内容: ${operationLog.oper_content}
操作人: ${operationLog.oper_by}
操作时间: ${operationLog.oper_time}
操作IP: ${operationLog.ip}
备注: ${operationLog.remark}
岗位ID: ${position.id}
UUID: ${position.uuid}
公司ID: ${position.company_id}
部门ID: ${position.dept_id}
岗位名称: ${position.position_name}
岗位编码: ${position.position_code}
岗位类型: ${getPositionTypeText(position.position_type)}
排序: ${position.sort}
状态: ${position.status === 1 ? '正常' : '禁用'}
创建时间: ${position.create_time}
备注: ${position.remark}