信眾牌位範本,活動總疏文
This commit is contained in:
+137
-16
@@ -51,7 +51,7 @@
|
||||
max="80"
|
||||
v-model.number="globalMargin"
|
||||
@input="applyGlobalMargin" />
|
||||
<button @click.event="adjustAllMargins(1)">+</button>
|
||||
<button @click.prevent="adjustAllMargins(1)">+</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -62,7 +62,10 @@
|
||||
<hr />
|
||||
|
||||
<button class="action-btn save-btn" @click.prevent="saveData">
|
||||
1. 儲存至資料庫
|
||||
1. 儲存總疏文
|
||||
</button>
|
||||
<button class="action-btn save-btn" @click.prevent="saveAsTempData">
|
||||
1.1. 另存成範本
|
||||
</button>
|
||||
<button class="action-btn print-btn" @click.prevent="triggerPrint">
|
||||
2. 產生 PDF / 列印
|
||||
@@ -228,13 +231,45 @@ module.exports = {
|
||||
methods: {
|
||||
changeShuwenType() {
|
||||
console.log("changeShuwenType:", this.shuwenType)
|
||||
// 防呆:如果切換回「請選擇」,就清空畫面
|
||||
if (!this.shuwenType) {
|
||||
this.clearContent();
|
||||
this.defaultTemplate = "";
|
||||
return;
|
||||
}
|
||||
//去資料庫抓回他的消災或超薦的總疏文
|
||||
axios.post(HTTP_HOST + 'api/shuwens/GetActShuwen', { act_num: Number(this.num), shuwen_type: this.shuwenType })
|
||||
.then(response => {
|
||||
console.log(response)
|
||||
if (response && response.data && response.data.data) {
|
||||
let shuwenContent = response.data.data.contents
|
||||
document.getElementById("editor").innerHTML = `${shuwenContent}`;
|
||||
let data = response.data.data;
|
||||
|
||||
// 1. 帶入疏文內容
|
||||
if (data.contents) {
|
||||
document.getElementById("editor").innerHTML = data.contents;
|
||||
}
|
||||
|
||||
// 2. 帶入紙張大小與方向 (對應 DB 欄位 paper_size 與 direction)
|
||||
if (data.paper_size) {
|
||||
this.paperSize = data.paper_size;
|
||||
}
|
||||
if (data.direction) {
|
||||
this.paperOrientation = data.direction;
|
||||
}
|
||||
|
||||
// 3. 同步樣板下拉選單 (如果之前存檔有綁定樣板)
|
||||
if (data.shuwen_num) {
|
||||
this.defaultTemplate = data.shuwen_num;
|
||||
} else {
|
||||
this.defaultTemplate = "";
|
||||
}
|
||||
|
||||
// 4. 呼叫更新 Layout,讓白紙區塊實際變形
|
||||
this.updateLayout();
|
||||
} else {
|
||||
// 如果該活動還沒有存過這個類型的總疏文,就給予預設空白
|
||||
this.clearContent();
|
||||
this.defaultTemplate = "";
|
||||
}
|
||||
|
||||
})
|
||||
@@ -352,19 +387,105 @@ module.exports = {
|
||||
this.globalMargin = newVal;
|
||||
this.applyGlobalMargin();
|
||||
},
|
||||
saveAsTempData() {
|
||||
// 1. 隱藏選單與取消選取狀態,避免將選取的樣式存進去
|
||||
this.isMenuVisible = false;
|
||||
if (this.currentTargetLine) {
|
||||
this.currentTargetLine.classList.remove('selected-line');
|
||||
}
|
||||
|
||||
saveData() {
|
||||
this.isMenuVisible = false;
|
||||
if (this.currentTargetLine) {
|
||||
this.currentTargetLine.classList.remove('selected-line');
|
||||
}
|
||||
console.log(this.num, this.shuwenType, this.defaultTemplate);
|
||||
const editor = this.$refs.editorRef;
|
||||
if (editor) {
|
||||
console.log(editor.innerHTML);
|
||||
alert('已成功擷取 HTML 結構至 Console!');
|
||||
}
|
||||
},
|
||||
// 2. 檢核:必須要有疏文類型
|
||||
if (!this.shuwenType) {
|
||||
alert("請先選擇【疏文類型】(消災/超薦)!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 取得範本名稱 (使用原生 prompt,您也可以後續在 UI 加上 input)
|
||||
const templateName = prompt("請輸入新範本名稱:");
|
||||
if (!templateName || templateName.trim() === "") {
|
||||
return; // 使用者按取消或未輸入
|
||||
}
|
||||
|
||||
// 4. 取得編輯器內的 HTML 內容
|
||||
const editor = this.$refs.editorRef;
|
||||
const htmlContent = editor ? editor.innerHTML : '';
|
||||
|
||||
// 5. 組合 API Payload (對應 dbo.shuwen_temp 資料表)
|
||||
// 註:num 為 IDENTITY(1,1) 自動遞增,不需傳入
|
||||
// 註:reg_time 通常由後端 DB 的 GETDATE() 或程式產生,此處不強制傳入
|
||||
const payload = {
|
||||
shuwen_type: this.shuwenType,
|
||||
name: templateName.trim(),
|
||||
contents: htmlContent
|
||||
};
|
||||
|
||||
console.log('準備另存疏文範本:', payload);
|
||||
|
||||
// 6. 發送 API 請求 (請依據您的實際路由進行修改)
|
||||
axios.post(HTTP_HOST + 'api/shuwens/SaveAsShuwenTemplate', payload)
|
||||
.then(response => {
|
||||
if (response.status==200) {
|
||||
alert('另存範本成功!');
|
||||
// 重新抓取範本清單,讓下拉選單即時更新
|
||||
this.initData();
|
||||
} else {
|
||||
alert('存檔失敗');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('另存範本發生錯誤:', error);
|
||||
alert('存檔發生錯誤');
|
||||
});
|
||||
},
|
||||
|
||||
saveData() {
|
||||
// 1. 隱藏選單與取消選取狀態
|
||||
this.isMenuVisible = false;
|
||||
if (this.currentTargetLine) {
|
||||
this.currentTargetLine.classList.remove('selected-line');
|
||||
}
|
||||
|
||||
// 2. 檢核:確認活動編號與疏文類型
|
||||
if (!this.num) {
|
||||
alert("缺少活動編號 (act_num),無法儲存!");
|
||||
return;
|
||||
}
|
||||
if (!this.shuwenType) {
|
||||
alert("請先選擇【疏文類型】(消災/超薦)!");
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. 取得編輯器內的 HTML 內容
|
||||
const editor = this.$refs.editorRef;
|
||||
const htmlContent = editor ? editor.innerHTML : '';
|
||||
|
||||
// 4. 組合 API Payload (對應 dbo.activity_shuwen 資料表)
|
||||
// 註:act_num 與 shuwen_type 為 PK 複合主鍵
|
||||
const payload = {
|
||||
act_num: Number(this.num),
|
||||
shuwen_num: this.defaultTemplate ? Number(this.defaultTemplate) : null,
|
||||
shuwen_type: this.shuwenType,
|
||||
contents: htmlContent,
|
||||
paper_size: this.paperSize,
|
||||
direction: this.paperOrientation
|
||||
};
|
||||
|
||||
console.log('準備儲存活動總疏文:', payload);
|
||||
|
||||
// 5. 發送 API 請求 (請依據您的實際路由進行修改)
|
||||
axios.post(HTTP_HOST + 'api/shuwens/SaveActShuwen', payload)
|
||||
.then(response => {
|
||||
if (response.status==200) {
|
||||
alert('總疏文儲存成功!');
|
||||
} else {
|
||||
alert('存檔失敗');
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('儲存活動疏文發生錯誤:', error);
|
||||
alert('存檔發生錯誤');
|
||||
});
|
||||
},
|
||||
|
||||
triggerPrint() {
|
||||
//window.print();
|
||||
|
||||
Reference in New Issue
Block a user