|
@@ -1,3 +1,126 @@
|
|
|
+SwfType = {
|
|
|
+ "other_furniture": "其他",
|
|
|
+ "master_bedroom": "臥室",
|
|
|
+ "living_room": "客廳",
|
|
|
+ "study_room": "書房",
|
|
|
+ "dining_room": "餐廳",
|
|
|
+};
|
|
|
+
|
|
|
+//document.ready
|
|
|
+$(function () {
|
|
|
+
|
|
|
+ $("#dialog-form").hide();
|
|
|
+ editor = new EditorJS({
|
|
|
+ readOnly: false,
|
|
|
+ holder: 'editorjs',
|
|
|
+ });
|
|
|
+ editor1 = new EditorJS({
|
|
|
+ readOnly: false,
|
|
|
+ holder: 'editorjs1',
|
|
|
+ });
|
|
|
+
|
|
|
+});
|
|
|
+
|
|
|
+frontMatters = [];
|
|
|
+contentMatters = [];
|
|
|
+
|
|
|
+function getHeader(url) {
|
|
|
+ axios.get(contentApiUrl + url).then(({ data }) => {
|
|
|
+ frontMatters = [];
|
|
|
+ contentMatters = [];
|
|
|
+ editTarget = url;
|
|
|
+ mdType = url.split('/')[1];
|
|
|
+ aa = data[0]['content'];
|
|
|
+ const content = _.get(data, '0.content', '');
|
|
|
+ blocks = parseMd(aa);
|
|
|
+ oTitle = $("#ctitle").val();
|
|
|
+ // $("#dialog-form").dialog();
|
|
|
+ if ($("#ctype").val() == "collection") {
|
|
|
+ $("#scat").hide();
|
|
|
+ }
|
|
|
+ else if ($("#ctype").val() == "blog") {
|
|
|
+ $("#sdesc").hide();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ ParseProductSection(contentMatters.join(''));
|
|
|
+ }
|
|
|
+ $("#myModal").modal();
|
|
|
+
|
|
|
+ //console.log(frontMatters);
|
|
|
+ //alert($('#cimage').val());
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function toggleDraft(obj, url) {
|
|
|
+ axios.get(contentApiUrl + url).then(({ data }) => {
|
|
|
+ frontMatters = [];
|
|
|
+ contentMatters = [];
|
|
|
+ aa = data[0]['content'];
|
|
|
+ const content = _.get(data, '0.content', '');
|
|
|
+ blocks = parseMd(aa);
|
|
|
+ editTarget = url;
|
|
|
+ $('#cdraft').removeAttr('checked');
|
|
|
+ $('#cdraft').prop('checked', obj.checked);
|
|
|
+ updateHeader();
|
|
|
+ oTitle = "";
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function updateHeader() {
|
|
|
+ /* if (oTitle != $('#ctitle').val() && $('#ctitle').val() != "" && oTitle != "") {
|
|
|
+ axios.get('/backstage/modTitle/' + oTitle + '/' + $('#ctitle').val()).then(({ data }) => {
|
|
|
+ if (data.success == "0") {
|
|
|
+ alert('已有重複的標題,請重新設定');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ writeMd();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ writeMd();
|
|
|
+ } */
|
|
|
+ $("#uptbtn").attr('disabled', true);
|
|
|
+ writeMd();
|
|
|
+ // location.reload();
|
|
|
+}
|
|
|
+
|
|
|
+function writeMd() {
|
|
|
+
|
|
|
+ axios.get('/backstage/utils?trantext=' + $('#ccategories').val()).then(({ data }) => { $('#ccol1').val(data); })
|
|
|
+ .finally(() => {
|
|
|
+ mdContent = GetMdHeader();
|
|
|
+ mdContent += contentMatters.join("\n");
|
|
|
+ var formData = new FormData();
|
|
|
+ var imagefile = document.querySelector('#cfile');
|
|
|
+ if (imagefile != null)
|
|
|
+ formData.append("image", imagefile.files[0]);
|
|
|
+ axios.post('/backstage/upload/title', formData, {
|
|
|
+ headers: {
|
|
|
+ 'Content-Type': 'multipart/form-data'
|
|
|
+ }
|
|
|
+ }).then(({ data }) => {
|
|
|
+ $('#cfile').val("");
|
|
|
+ if (data.success == "1") {
|
|
|
+ mdContent = mdContent.replace($('#cimage').val(), '/img/collection/' + data.file.url.substring(data.file.url.lastIndexOf('/') + 1));
|
|
|
+ //alert(data.file.url.substring(data.file.url.lastIndexOf('/')+1));
|
|
|
+ }
|
|
|
+
|
|
|
+ postData = {
|
|
|
+ content: mdContent,
|
|
|
+ url: editTarget
|
|
|
+ };
|
|
|
+ //console.log(mdContent);
|
|
|
+ axios.post(contentApiUrl + editTarget, json = postData).then(({ data }) => {
|
|
|
+ });
|
|
|
+ }).finally(() => {
|
|
|
+ alert('資料已更新'); // test
|
|
|
+ location.reload();
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
function parseMd(content) {
|
|
|
//var frontMatters = [];
|
|
|
var blockCount;
|
|
@@ -229,6 +352,345 @@ function tableArrayToHtml(tableArray) {
|
|
|
return tbl.outerHTML.toString();
|
|
|
}
|
|
|
|
|
|
+function GenSwfDD(obj) {
|
|
|
+ Object.entries(SwfType).forEach(([key, value]) => {
|
|
|
+ op = document.createElement('option');
|
|
|
+ op.value = key;
|
|
|
+ op.text = value;
|
|
|
+ obj.appendChild(op);
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+function ReplaceSwfType(inContent) {
|
|
|
+ Object.entries(SwfType).forEach(([key, value]) => {
|
|
|
+ inContent = inContent.replaceAll('[' + key + ']', '[' + value + ']');
|
|
|
+ });
|
|
|
+ return inContent;
|
|
|
+}
|
|
|
+
|
|
|
+var editor;
|
|
|
+var editor1;
|
|
|
+editorBlocks = [];
|
|
|
+editorBlocks1 = [];
|
|
|
+function ParseProductSection(inContent) {
|
|
|
+ editorBlocks = [];
|
|
|
+ editorBlocks1 = [];
|
|
|
+
|
|
|
+ var aa = $.parseHTML(inContent.trim());
|
|
|
+ //處理圖片
|
|
|
+ if ($("[id='carousel-with-preview']", aa).length > 0) {
|
|
|
+ imgnodes = $("[id='carousel-with-preview']", aa)[0].childNodes;
|
|
|
+ for (i = 0; i < imgnodes.length; i++) {
|
|
|
+ var tmpsrc, tmpw, tmph, ampimg;
|
|
|
+ if (imgnodes[i].nodeName == "AMP-IMG") {
|
|
|
+ //alert(imgnodes[i].nodeName);
|
|
|
+ ampimg = imgnodes[i].outerHTML;
|
|
|
+ tmpsrc = ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("src=\"") + 5) - ampimg.indexOf("src=\"") - 5);
|
|
|
+ //alert(tmpsrc);
|
|
|
+ tmpw = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
|
|
|
+ tmph = ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8);
|
|
|
+ //tmph = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
|
|
|
+ editorBlocks.push({
|
|
|
+ type: "image", data: {
|
|
|
+ file: {
|
|
|
+ url: BHOUSE_SERVER + editTarget + '/' + tmpsrc,
|
|
|
+ width: parseInt(tmpw),
|
|
|
+ height: parseInt(tmph),
|
|
|
+ },
|
|
|
+ caption: "小寶優居 | " + $('#ctitle').val(),
|
|
|
+ stretched: false,
|
|
|
+ withBorder: true,
|
|
|
+ withBackground: false,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ editorBlocks.push({
|
|
|
+ type: "image", data: {
|
|
|
+ file: {
|
|
|
+ url: 'https://bhouse.com.tw/img/logo2.png',
|
|
|
+ width: 300,
|
|
|
+ height: 300,
|
|
|
+ },
|
|
|
+ caption: "小寶優居 | ",
|
|
|
+ stretched: false,
|
|
|
+ withBorder: true,
|
|
|
+ withBackground: false,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //editor.api.blocks.render(editorBlocks);
|
|
|
+ $('#editorjs')[0].innerHTML = "";
|
|
|
+ editor = new EditorJS({
|
|
|
+ readOnly: false,
|
|
|
+ holder: 'editorjs',
|
|
|
+ tools: {
|
|
|
+ paragraph: { inlineToolbar: false },
|
|
|
+ image: {
|
|
|
+ class: ImageTool,
|
|
|
+ config: {
|
|
|
+ endpoints: {
|
|
|
+ byFile: '/backstage/upload' + $('#curl').val(),
|
|
|
+ byUrl: '/backstage/getimage' + $('#curl').val(),
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ , data: { blocks: editorBlocks }
|
|
|
+ ,
|
|
|
+ onReady: function () {
|
|
|
+ //alert(editor.blocks.getBlocksCount());
|
|
|
+ //saveButton.click();
|
|
|
+ },
|
|
|
+ onChange: function (api, block) {
|
|
|
+ //$('#cimage')[0].val();
|
|
|
+ //console.log('something changed', block);
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //類別
|
|
|
+ Object.entries(SwfType).forEach(([key, value]) => {
|
|
|
+ if ($("#ctype").val() == key) {
|
|
|
+ //alert($("#ctype").val());
|
|
|
+ $("#swfDropdown").val($("#ctype").val());
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ //敘述
|
|
|
+ if ($("[class='description']", aa).length > 0) {
|
|
|
+ $("#swfDesc").val($(".description", aa)[0].innerHTML.trim().replaceAll('<b>', '').replaceAll('</b>', ''));
|
|
|
+ }
|
|
|
+ //alert(editorBlocks);
|
|
|
+ //其他
|
|
|
+ if ($("[class='detail']", aa).length > 0) {
|
|
|
+ onodes = $("[class='detail']", aa)[0].childNodes;
|
|
|
+ for (i = 0; i < onodes.length; i++) {
|
|
|
+ if (onodes[i].nodeName != "#text") {
|
|
|
+ if (onodes[i].innerHTML.trim().indexOf("定價 : ") >= 0)
|
|
|
+ $("#swfPrice").val(onodes[i].innerHTML.replace("定價 : ", "").trim());
|
|
|
+ if (onodes[i].innerHTML.trim().indexOf("顏色 : ") >= 0)
|
|
|
+ $("#swfColor").val(onodes[i].innerHTML.replace("顏色 : ", "").trim());
|
|
|
+ if (onodes[i].innerHTML.trim().indexOf("尺寸(mm) : ") >= 0)
|
|
|
+ $("#swfSize").val(onodes[i].innerHTML.replace("尺寸(mm) : ", "").trim());
|
|
|
+ if (onodes[i].innerHTML.trim().indexOf("材質 : ") >= 0)
|
|
|
+ $("#swfMat").val(onodes[i].innerHTML.replace("材質 : ", "").trim());
|
|
|
+ if (onodes[i].innerHTML.trim().indexOf("備註 : ") >= 0)
|
|
|
+ $("#swfMemo").val(onodes[i].innerHTML.replace("備註 : ", "").trim());
|
|
|
+ //alert(nodes[i].innerHTML);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //處理規格圖片
|
|
|
+ if ($("[class='spec']", aa).length > 0) {
|
|
|
+ snodes = $("[class='spec']", aa)[0].childNodes;
|
|
|
+ //alert(snodes[0].innerHTML);
|
|
|
+ for (i = 0; i < snodes.length; i++) {
|
|
|
+ var tmpsrc, tmpw, tmph, ampimg;
|
|
|
+ if (snodes[i].nodeName == "AMP-IMG") {
|
|
|
+ ampimg = snodes[i].outerHTML;
|
|
|
+ tmpsrc = ampimg.substr(ampimg.indexOf("src=\"") + 5, ampimg.indexOf("\"", ampimg.indexOf("src=\"") + 5) - ampimg.indexOf("src=\"") - 5);
|
|
|
+ tmpw = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
|
|
|
+ tmph = ampimg.substr(ampimg.indexOf("height=\"") + 8, ampimg.indexOf("\"", ampimg.indexOf("height=\"") + 8) - ampimg.indexOf("height=\"") - 8);
|
|
|
+ //tmph = ampimg.substr(ampimg.indexOf("width=\"") + 7, ampimg.indexOf("\"", ampimg.indexOf("width=\"") + 7) - ampimg.indexOf("width=\"") - 7);
|
|
|
+ editorBlocks1.push({
|
|
|
+ type: "image", data: {
|
|
|
+ file: {
|
|
|
+ url: BHOUSE_SERVER + editTarget + '/' + tmpsrc,
|
|
|
+ width: parseInt(tmpw),
|
|
|
+ height: parseInt(tmph),
|
|
|
+ },
|
|
|
+ caption: "小寶優居 | " + $('#ctitle').val(),
|
|
|
+ stretched: false,
|
|
|
+ withBorder: true,
|
|
|
+ withBackground: false,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ editorBlocks1.push({
|
|
|
+ type: "image", data: {
|
|
|
+ file: {
|
|
|
+ url: 'https://bhouse.com.tw/img/logo2.png',
|
|
|
+ width: 300,
|
|
|
+ height: 300,
|
|
|
+ },
|
|
|
+ caption: "小寶優居 | ",
|
|
|
+ stretched: false,
|
|
|
+ withBorder: true,
|
|
|
+ withBackground: false,
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ $('#editorjs1')[0].innerHTML = "";
|
|
|
+ editor1 = new EditorJS({
|
|
|
+ readOnly: false,
|
|
|
+ holder: 'editorjs1',
|
|
|
+ tools: {
|
|
|
+ paragraph: { inlineToolbar: false },
|
|
|
+ image: {
|
|
|
+ class: ImageTool,
|
|
|
+ config: {
|
|
|
+ endpoints: {
|
|
|
+ byFile: '/backstage/upload' + $('#curl').val(),
|
|
|
+ byUrl: '/backstage/getimage' + $('#curl').val(),
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ , data: { blocks: editorBlocks1 }
|
|
|
+ ,
|
|
|
+ onReady: function () {
|
|
|
+ //saveButton.click();
|
|
|
+ },
|
|
|
+ onChange: function (api, block) {
|
|
|
+ //console.log('something changed', block);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function GenProductSection(mimg, specimg) {
|
|
|
+
|
|
|
+ section = document.createElement('section')
|
|
|
+ tmpstr = `<section class="section44 mb-5">
|
|
|
+ <div class="container">
|
|
|
+ <div class="mb-5">
|
|
|
+ <a href="/solid_wood_furniture">關於設計家具</a> > <a href="/##ctype##">##ctypec##</a> > <a href="##curl##">##ctitle##</a>
|
|
|
+ </div>
|
|
|
+ <div class="row">
|
|
|
+ <div class="col-md-5 col-sm-12">
|
|
|
+ <div class="block">
|
|
|
+ <div class="section-title text-center">
|
|
|
+ <amp-carousel
|
|
|
+ id="carousel-with-preview"
|
|
|
+ width="300"
|
|
|
+ height="300"
|
|
|
+ layout="responsive"
|
|
|
+ type="slides"
|
|
|
+ autoplay
|
|
|
+ delay="2500"
|
|
|
+ role="region"
|
|
|
+ aria-label="小寶優居 | ##ctitle##"
|
|
|
+ >
|
|
|
+ ##AMP-IMG##
|
|
|
+ </amp-carousel>
|
|
|
+ <div class="mt-3 carousel-preview">
|
|
|
+ ##PREV-IMG##
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="col-md-7 col-sm-12">
|
|
|
+ <div class="block ms-md-5 mb-5">
|
|
|
+ <div class="title mb-4"><b>##ctitle##</b></div>
|
|
|
+ <div class="description">
|
|
|
+ <b>##swfDesc##</b>
|
|
|
+ </div>
|
|
|
+ <hr>
|
|
|
+ <div class="detail">
|
|
|
+ ##swfPrice##
|
|
|
+ ##swfColor##
|
|
|
+ ##swfSize##
|
|
|
+ ##swfMat##
|
|
|
+ ##swfMemo##
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="card">
|
|
|
+ <div class="card-body text-center">
|
|
|
+ <div class="mb-2">1.商品顏色因拍攝、螢幕差異略有不同,實際顏色請依照門市實際顏色為主</div>
|
|
|
+ <div>2.部分商品因應空間大小,保有客製尺寸服務,詳細客製尺寸,請預約門市諮詢訂購</div>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <div class="spec">
|
|
|
+ <div class="mb-4"><b>尺寸規格</b></div>
|
|
|
+ ##SPEC-IMG##
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ </section>`;
|
|
|
+
|
|
|
+ tmpstr = tmpstr.replaceAll('##ctitle##', $("#ctitle").val());
|
|
|
+ tmpstr = tmpstr.replaceAll('##ctype##', $("#ctype").val());
|
|
|
+ tmpstr = tmpstr.replaceAll('##curl##', $("#curl").val());
|
|
|
+ Object.entries(SwfType).forEach(([key, value]) => {
|
|
|
+ if ($("#ctype").val() == key)
|
|
|
+ tmpstr = tmpstr.replaceAll('##ctypec##', value);
|
|
|
+ });
|
|
|
+ tmpstr = tmpstr.replaceAll('##swfDesc##', $("#swfDesc").val());
|
|
|
+ if ($("#swfPrice").val() != "")
|
|
|
+ tmpstr = tmpstr.replaceAll('##swfPrice##', "<div>定價 : " + $("#swfPrice").val() + "</div>");
|
|
|
+ if ($("#swfColor").val() != "")
|
|
|
+ tmpstr = tmpstr.replaceAll('##swfColor##', "<div>顏色 : " + $("#swfColor").val() + "</div>");
|
|
|
+ if ($("#swfSize").val() != "")
|
|
|
+ tmpstr = tmpstr.replaceAll('##swfSize##', "<div>尺寸(mm) : " + $("#swfSize").val() + "</div>");
|
|
|
+ if ($("#swfMat").val() != "")
|
|
|
+ tmpstr = tmpstr.replaceAll('##swfMat##', "<div>材質 : " + $("#swfMat").val() + "</div>");
|
|
|
+ if ($("#swfMemo").val() != "")
|
|
|
+ tmpstr = tmpstr.replaceAll('##swfMemo##', "<div>備註 : " + $("#swfMemo").val() + "</div>");
|
|
|
+
|
|
|
+ mimgstr = "";
|
|
|
+ firstimg = true;
|
|
|
+ for (i = 0; i < mimg.blocks.length; i++) {
|
|
|
+ //alert(block.type);
|
|
|
+ block = mimg.blocks[i];
|
|
|
+ if (block.type == "image") {
|
|
|
+ iurl = block.data.file.url.split('/');
|
|
|
+ if (firstimg) {
|
|
|
+ $("#cimage").val($("#curl").val() + '/' + iurl[iurl.length - 1]);
|
|
|
+ firstimg = false;
|
|
|
+ }
|
|
|
+ mimgstr += '<amp-img\n alt="' + block.data.caption
|
|
|
+ + '"\n src="' + iurl[iurl.length - 1]
|
|
|
+ + '"\n height="' + block.data.file.height
|
|
|
+ + '"\n width="' + block.data.file.width
|
|
|
+ + '"\n layout="responsive">\n</amp-img>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tmpstr = tmpstr.replaceAll('##AMP-IMG##', mimgstr);
|
|
|
+
|
|
|
+ previmgstr = "";
|
|
|
+ for (i = 0; i < mimg.blocks.length; i++) {
|
|
|
+ //alert(block.type);
|
|
|
+ block = mimg.blocks[i];
|
|
|
+ if (block.type == "image") {
|
|
|
+ iurl = block.data.file.url.split('/');
|
|
|
+ previmgstr += (previmgstr == "" ? "" : '\n') + `<button on="tap:carousel-with-preview.goToSlide(index=` + i + `)">
|
|
|
+ <amp-img
|
|
|
+ src="`+ iurl[iurl.length - 1] + `"
|
|
|
+ width="40"
|
|
|
+ height="40"
|
|
|
+ alt="`+ block.data.caption + `"
|
|
|
+ ></amp-img>
|
|
|
+ </button>`;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tmpstr = tmpstr.replaceAll('##PREV-IMG##', previmgstr);
|
|
|
+
|
|
|
+ specimgstr = "";
|
|
|
+ for (i = 0; i < specimg.blocks.length; i++) {
|
|
|
+ //alert(block.type);
|
|
|
+ block = specimg.blocks[i];
|
|
|
+ if (block.type == "image") {
|
|
|
+ iurl = block.data.file.url.split('/');
|
|
|
+ specimgstr += '<amp-img\n alt="' + block.data.caption
|
|
|
+ + '"\n src="' + iurl[iurl.length - 1]
|
|
|
+ + '"\n height="' + block.data.file.height
|
|
|
+ + '"\n width="' + block.data.file.width
|
|
|
+ + '"\n layout="responsive">\n</amp-img>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tmpstr = tmpstr.replaceAll('##SPEC-IMG##', specimgstr);
|
|
|
+
|
|
|
+ return tmpstr;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
class MDParser {
|
|
|
|
|
|
constructor(MDtext) {
|