# -*- coding: utf-8 -*- """ 添加部門職責頁籤和修正檢視按鈕功能 """ import sys import codecs if sys.platform == 'win32': sys.stdout = codecs.getwriter('utf-8')(sys.stdout.buffer, 'strict') sys.stderr = codecs.getwriter('utf-8')(sys.stderr.buffer, 'strict') # 讀取 index.html with open('index.html', 'r', encoding='utf-8') as f: content = f.read() # ==================== 1. 修正檢視按鈕功能 ==================== old_view_function = ''' // 檢視崗位 function viewPosition(code) { const position = positionListData.find(p => p.positionCode === code); if (position) { showToast('檢視崗位: ' + position.positionName); } }''' new_view_function = ''' // 檢視崗位 - 切換到崗位基礎資料頁籤並載入資料 function viewPosition(code) { const position = positionListData.find(p => p.positionCode === code); if (position) { // 切換到崗位基礎資料模組 document.querySelectorAll('.module-btn').forEach(b => { b.classList.remove('active', 'job-active', 'desc-active'); }); document.querySelector('.module-btn[data-module="position"]').classList.add('active'); document.querySelectorAll('.module-content').forEach(m => m.classList.remove('active')); document.getElementById('module-position').classList.add('active'); // 填入崗位資料 document.getElementById('positionCode').value = position.positionCode || ''; document.getElementById('positionName').value = position.positionName || ''; // 根據崗位類別設定下拉選單 const categoryMap = {'技術職': '01', '管理職': '02', '業務職': '03', '行政職': '04', '專業職': '05'}; const categoryCode = categoryMap[position.positionCategory] || ''; document.getElementById('positionCategory').value = categoryCode; if (typeof updateCategoryName === 'function') updateCategoryName(); document.getElementById('headcount').value = position.headcount || ''; document.getElementById('effectiveDate').value = position.effectiveDate || ''; // 填入組織欄位 if (document.getElementById('businessUnit')) { document.getElementById('businessUnit').value = position.businessUnit || ''; } if (document.getElementById('department')) { document.getElementById('department').value = position.department || ''; } showToast('已載入崗位: ' + position.positionName); } }''' if old_view_function in content: content = content.replace(old_view_function, new_view_function) print("[OK] Fixed viewPosition function") else: print("[INFO] viewPosition function pattern not found or already updated") # ==================== 2. 添加部門職責頁籤按鈕 ==================== # 在崗位描述按鈕後面添加部門職責按鈕 old_module_buttons = ''' 崗位描述 ''' new_module_buttons = ''' 部門職責 崗位描述 ''' if old_module_buttons in content and 'data-module="deptfunction"' not in content: content = content.replace(old_module_buttons, new_module_buttons) print("[OK] Added Department Function tab button") else: print("[INFO] Department Function tab button already exists or pattern not found") # ==================== 3. 添加部門職責模組內容 ==================== # 在崗位描述模組之前添加部門職責模組 dept_function_module = ''' 部門職責維護 Department Function Management ✨ I'm feeling lucky 匯入 CSV 匯出 CSV 部門職責編號 * 部門職責名稱 * 事業體 (Business Unit) * -- 請選擇 -- SBU - 業務事業體 MBU - 製造事業體 HQBU - 總部事業體 ITBU - 資訊事業體 HRBU - 人資事業體 ACCBU - 財會事業體 部門名稱 * 部門主管職稱 生效日期 * 部門人數上限 部門狀態 啟用中 停用 規劃中 部門使命 (Mission) 部門願景 (Vision) 核心職責 (Core Functions) * 關鍵績效指標 (KPIs) 協作部門 備注 清除 取消 存檔續建 存檔離開 ''' # 在崗位描述模組之前插入 jobdesc_module_start = '