You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

326 lines
9.5 KiB

var domino, window, document, location, Vue, VueRouter, vuessr, navigator, axios, Promise, GoUseCall, GoUse,
GoUseRegistered,
govueId, useRoute, goUseCallCache, $, jQuery, GoParam, qs, Intl, process, Node;
var global = this;
global.Vue = Vue;
global.VueRouter = VueRouter;
global.Intl = Intl;
global.process = process;
global.Node = Node;
process = {
env: {
VUE_ENV: "server",
NODE_ENV: "production"
}
};
navigator = {
userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 a/537.36 "
};
var net = {
request: function (c) {
var url = c["url"];
var data = c["data"];
var header = c["header"];
var method = c["method"];
var dataType = c["dataType"];
var timeout = c["timeout"];
var success = c["success"];
var fail = c["fail"];
var complete = c["complete"];
var isHost = url.indexOf("http://") > -1 || url.indexOf("https://") > -1;
var isAbs = (url[0] == '/');
if (!isHost) {
if (!isAbs) {
url = location.pathname + "/" + url
}
url = location.host + "/" + url;
for (; url.indexOf("//") > -1;) {
url = url.replace("//", "/")
}
url = location.protocol + "//" + url
}
if (data) {
if (method == "GET") {
url = $.param.querystring(url, data);
data = ""
} else {
if (typeof (data) == "object") {
if (header["Content-Type"].indexOf("application/json") > -1 || header["content-type"].indexOf("application/json") > -1) {
data = JSON.stringify(data);
} else {
data = $.param(data);
}
}
}
}
var resp = GoRequest({
url: url,
data: data,
method: method,
header: header,
timeout: timeout
});
resp = JSON.parse(resp);
var statusCode = resp["statusCode"];
var result = resp["data"];
if (dataType == "json") {
result = JSON.parse(result)
}
if (statusCode == 200) {
success && success({
data: result,
statusCode: statusCode + "",
});
} else {
fail && fail({
data: result,
statusCode: statusCode + "",
})
}
// complete && complete({
// data: result,
// statusCode: statusCode + "",
// })
}
};
function GoVueRender(template, app, context) {
var raw = GoReadFile(template);
// console.log(vuessr);
var renderer = vuessr.createRenderer({
template: raw
});
// 第 3 步:将 Vue 实例渲染为 HTML
renderer.renderToString(app, context, function (err, html) {
if (err) throw err;
GoReturn(html);
// => <div data-server-rendered="true">Hello World</div>
})
}
function LoadPage(src, href) {
window = domino.createWindow(src, href);
document = window.document;
location = window.location;
for (var i in global) {
window[i] = global[i]
}
}
/**
* 获取页面Id
* @return {string}
*/
function GetGoVueId() {
var h = document.querySelector("[gv-id]")
var id = "";
if (h) {
id = h.getAttribute("gv-id");
}
return id;
}
/**
* 执行内联的javascript
*/
function RunInlineCode() {
var jsInline = document.getElementsByTagName("script");
var jsInlineFiles = [];
for (var i = jsInline.length - 1; i >= 0; i--) {
var isGoVueSrc = jsInline[i].hasAttribute("gv-src");
var isGoVuePrivate = jsInline[i].hasAttribute("gv-private");
if (isGoVueSrc) {
var res = {};
var file = jsInline[i].getAttribute("src");
if (jsInline[i].hasAttribute("src") && file != "") {
res["file"] = file
}
if (jsInline[i].text && jsInline[i].text != "") {
res["src"] = jsInline[i].text;
}
if (res["file"] || res["src"]) {
jsInlineFiles.unshift(res);
}
if (isGoVuePrivate) {
jsInline[i].remove();
} else {
jsInline[i].removeAttribute("gv-src");
}
}
}
for (var i in jsInlineFiles) {
if (jsInlineFiles[i]["file"]) {
console.log("load file", jsInlineFiles[i]["file"]);
GoRunCodeByFile(jsInlineFiles[i]["file"]);
}
if (jsInlineFiles[i]["src"]) {
GoRunCode(jsInlineFiles[i]["src"]);
}
}
}
/**
* 载入页面传入的参数
*/
function LoadGoParam() {
GoParam = jQuery.deparam(GoQuery);
}
/**
* 忽略标签操作
*/
var GoVueIgnore = function () {
var gv_ignore_tag_map = {};
var gv_ignore_class_map = {};
var gv_ignore_len = 0;
var gv_ignore_class_len = 0;
/**
* 忽略前置
*/
this.ignore = function () {
var templateTagNodes = document.getElementsByTagName("template");
for(var i = 0;i<templateTagNodes.length;i++){
templateTagNodes[i].outerHTML = templateTagNodes[i].outerHTML.replace(/<template/g,"<gv-template").replace(/<\/template>/g,"</gv-template>")
}
var gv_ignore = document.getElementsByTagName("gv-ignore");
gv_ignore_len = gv_ignore.length;
for (var i = gv_ignore_len - 1; i >= 0; i--) {
gv_ignore_tag_map[i] = gv_ignore[i].innerHTML;
gv_ignore[i].outerHTML = "<gv-ignore-" + i + "></gv-ignore-" + i + ">";
}
var gv_ignore_class = document.querySelectorAll("[gv-ignore]");
gv_ignore_class_len = gv_ignore_class.length;
// console.log(document.innerHTML);
// console.log("gv_ignore_class_len",gv_ignore_class_len)
for (var i = 0; i < gv_ignore_class_len; i++) {
if (!gv_ignore_class_map[i]) {
gv_ignore_class_map[i] = {};
}
var a = gv_ignore_class[i].attributes;
var len = gv_ignore_class[i].attributes.length;
var ignoreVal = gv_ignore_class[i].getAttribute("gv-ignore");
for (var k = len - 1; k >= 0; k--) {
if (!ignoreVal || ignoreVal == "" || ignoreVal.split("|").includes(a.item(k).name)) {
gv_ignore_class_map[i][a.item(k).name] = a.item(k).value;
gv_ignore_class[i].removeAttribute(a.item(k).name);
}
}
gv_ignore_class[i].removeAttribute("gv-ignore");
gv_ignore_class[i].setAttribute("gv-ignore-val", "gv-ignore-" + i)
}
var templateTagNodes = document.getElementsByTagName("gv-template");
for(var i = 0;i<templateTagNodes.length;i++){
templateTagNodes[i].outerHTML = templateTagNodes[i].outerHTML.replace(/<gv-template/g,"<template").replace(/<\/gv-template>/g,"</template>")
}
};
/**
* 恢复忽略内容等待渲染
*/
this.restore = function () {
var gv_restore, i, k, j;
for (i = 0; i < gv_ignore_len; i++) {
gv_restore = document.getElementsByTagName("gv-ignore-" + i);
for (k = 0; k < gv_restore.length; k++) {
gv_restore[k].outerHTML = gv_ignore_tag_map[i];
}
}
for (i = 0; i < gv_ignore_class_len; i++) {
gv_restore = document.querySelectorAll("[gv-ignore-val='gv-ignore-" + i + "']");
for (k = 0; k < gv_restore.length; k++) {
for (j in gv_ignore_class_map[i]) {
gv_restore[k].setAttribute(j, gv_ignore_class_map[i][j]);
}
gv_restore[k].removeAttribute("gv-ignore-val");
}
}
}
};
//自动替换事件属性,不成熟实用性不足,不启用
var GoVueIgnoreOnEvent = function () {
var all = document.querySelectorAll('*');
all.forEach(function (el) {
var len = el.attributes.length;
var arr = [];
var arr2 = [];
for (var i = 0; i < len; i++) {
var name = el.attributes.item(i).name;
if (name[0] == "@" || name.indexOf("v-on:") == 0) {
arr.push({
name: name.replace("v-on:", "gv-on:").replace("@", "gv-on:"),
value: el.attributes.item(i).value,
});
arr2.push({
name: ":data-" + name.replace("v-on:", "gv-on:").replace("@", "gv-on:"),
value: el.attributes.item(i).value.match(/\((.+?)\)/g),
});
// el.setAttribute("gv-on:" + name, el.attributes.item(i).value);
// el.setAttribute(":gv-on-data:" + name, el.attributes.item(i).value.match(/\((.+?)\)/g));
}
}
for (var i in arr) {
console.log(JSON.stringify(arr[i]));
el.setAttribute(arr[i].name, arr[i].value);
el.setAttribute(arr2[i].name, arr2[i].value);
}
})
};
if (!HTMLDecode) {
function HTMLDecode(text) {
var temp = document.createElement("div");
temp.innerHTML = text;
var output = temp.innerText || temp.textContent;
temp = null;
return output;
}
}
function GoVueRestoreRawTemplate() {
var template = document.getElementsByTagName("gv-template-html");
for (var i in template) {
template[i].outerHTML = Base64Decode(template[i].innerHTML);
}
}