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.

310 lines
8.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. var domino, window, document, location, Vue, VueRouter, vuessr, navigator, axios, Promise, GoUseCall, GoUse,
  2. GoUseRegistered,
  3. govueId, useRoute, goUseCallCache, $, jQuery, GoParam, qs, Intl, process, Node;
  4. var global = this;
  5. global.Vue = Vue;
  6. global.VueRouter = VueRouter;
  7. global.Intl = Intl;
  8. global.process = process;
  9. global.Node = Node;
  10. process = {
  11. env: {
  12. VUE_ENV: "server",
  13. NODE_ENV: "production"
  14. }
  15. };
  16. navigator = {
  17. userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 a/537.36 "
  18. };
  19. var net = {
  20. request: function (c) {
  21. var url = c["url"];
  22. var data = c["data"];
  23. var header = c["header"];
  24. var method = c["method"];
  25. var dataType = c["dataType"];
  26. var timeout = c["timeout"];
  27. var success = c["success"];
  28. var fail = c["fail"];
  29. var complete = c["complete"];
  30. var isHost = url.indexOf("http://") > -1 || url.indexOf("https://") > -1;
  31. var isAbs = (url[0] == '/');
  32. if (!isHost) {
  33. if (!isAbs) {
  34. url = location.pathname + "/" + url
  35. }
  36. url = location.host + "/" + url;
  37. for (; url.indexOf("//") > -1;) {
  38. url = url.replace("//", "/")
  39. }
  40. url = location.protocol + "//" + url
  41. }
  42. if (data) {
  43. if (method == "GET") {
  44. url = $.param.querystring(url, data);
  45. data = ""
  46. } else {
  47. if (typeof (data) == "object") {
  48. if (header["Content-Type"].indexOf("application/json") > -1 || header["content-type"].indexOf("application/json") > -1) {
  49. data = JSON.stringify(data);
  50. } else {
  51. data = $.param(data);
  52. }
  53. }
  54. }
  55. }
  56. var resp = GoRequest({
  57. url: url,
  58. data: data,
  59. method: method,
  60. header: header,
  61. timeout: timeout
  62. });
  63. resp = JSON.parse(resp);
  64. var statusCode = resp["statusCode"];
  65. var result = resp["data"];
  66. if (dataType == "json") {
  67. result = JSON.parse(result)
  68. }
  69. if (statusCode == 200) {
  70. success && success({
  71. data: result,
  72. statusCode: statusCode + "",
  73. });
  74. } else {
  75. fail && fail({
  76. data: result,
  77. statusCode: statusCode + "",
  78. })
  79. }
  80. // complete && complete({
  81. // data: result,
  82. // statusCode: statusCode + "",
  83. // })
  84. }
  85. };
  86. function GoVueRender(template, app, context) {
  87. var raw = GoReadFile(template);
  88. console.log(vuessr);
  89. var renderer = vuessr.createRenderer({
  90. template: raw
  91. });
  92. // 第 3 步:将 Vue 实例渲染为 HTML
  93. renderer.renderToString(app, context, function (err, html) {
  94. if (err) throw err;
  95. GoReturn(html);
  96. // => <div data-server-rendered="true">Hello World</div>
  97. })
  98. }
  99. function LoadPage(src, href) {
  100. window = domino.createWindow(src, href);
  101. document = window.document;
  102. location = window.location;
  103. for (var i in global) {
  104. window[i] = global[i]
  105. }
  106. }
  107. /**
  108. * 获取页面Id
  109. * @return {string}
  110. */
  111. function GetGoVueId() {
  112. var h = document.querySelector("[gv-id]")
  113. var id = "";
  114. if (h) {
  115. id = h.getAttribute("gv-id");
  116. }
  117. return id;
  118. }
  119. /**
  120. * 执行内联的javascript
  121. */
  122. function RunInlineCode() {
  123. var jsInline = document.getElementsByTagName("script");
  124. var jsInlineFiles = [];
  125. for (var i = jsInline.length - 1; i >= 0; i--) {
  126. var isGoVueSrc = jsInline[i].hasAttribute("gv-src");
  127. var isGoVuePrivate = jsInline[i].hasAttribute("gv-private");
  128. if (isGoVueSrc) {
  129. var res = {};
  130. var file = jsInline[i].getAttribute("src");
  131. if (jsInline[i].hasAttribute("src") && file != "") {
  132. res["file"] = file
  133. }
  134. if (jsInline[i].text && jsInline[i].text != "") {
  135. res["src"] = jsInline[i].text;
  136. }
  137. if (res["file"] || res["src"]) {
  138. jsInlineFiles.unshift(res);
  139. }
  140. if (isGoVuePrivate) {
  141. jsInline[i].remove();
  142. } else {
  143. jsInline[i].removeAttribute("gv-src");
  144. }
  145. }
  146. }
  147. for (var i in jsInlineFiles) {
  148. if (jsInlineFiles[i]["file"]) {
  149. console.log("load file", jsInlineFiles[i]["file"]);
  150. GoRunCodeByFile(jsInlineFiles[i]["file"]);
  151. }
  152. if (jsInlineFiles[i]["src"]) {
  153. GoRunCode(jsInlineFiles[i]["src"]);
  154. }
  155. }
  156. }
  157. /**
  158. * 载入页面传入的参数
  159. */
  160. function LoadGoParam() {
  161. GoParam = jQuery.deparam(GoQuery);
  162. }
  163. /**
  164. * 忽略标签操作
  165. */
  166. var GoVueIgnore = function () {
  167. var gv_ignore_tag_map = {};
  168. var gv_ignore_class_map = {};
  169. var gv_ignore_len = 0;
  170. var gv_ignore_class_len = 0;
  171. /**
  172. * 忽略前置
  173. */
  174. this.ignore = function () {
  175. var gv_ignore = document.getElementsByTagName("gv-ignore");
  176. gv_ignore_len = gv_ignore.length;
  177. for (var i = gv_ignore_len - 1; i >= 0; i--) {
  178. gv_ignore_tag_map[i] = gv_ignore[i].innerHTML;
  179. gv_ignore[i].outerHTML = "<gv-ignore-" + i + "></gv-ignore-" + i + ">";
  180. }
  181. var gv_ignore_class = document.querySelectorAll("[gv-ignore]");
  182. gv_ignore_class_len = gv_ignore_class.length;
  183. // console.log("gv_ignore_class_len",gv_ignore_class_len)
  184. for (var i = 0; i < gv_ignore_class_len; i++) {
  185. if (!gv_ignore_class_map[i]) {
  186. gv_ignore_class_map[i] = {};
  187. }
  188. var a = gv_ignore_class[i].attributes;
  189. var len = gv_ignore_class[i].attributes.length;
  190. var ignoreVal = gv_ignore_class[i].getAttribute("gv-ignore");
  191. for (var k = len - 1; k >= 0; k--) {
  192. if (!ignoreVal || ignoreVal == "" || ignoreVal.split("|").includes(a.item(k).name)) {
  193. gv_ignore_class_map[i][a.item(k).name] = a.item(k).value;
  194. gv_ignore_class[i].removeAttribute(a.item(k).name);
  195. }
  196. }
  197. gv_ignore_class[i].removeAttribute("gv-ignore");
  198. gv_ignore_class[i].setAttribute("gv-ignore-val", "gv-ignore-" + i)
  199. }
  200. };
  201. /**
  202. * 恢复忽略内容等待渲染
  203. */
  204. this.restore = function () {
  205. var gv_restore, i, k, j;
  206. for (i = 0; i < gv_ignore_len; i++) {
  207. gv_restore = document.getElementsByTagName("gv-ignore-" + i);
  208. for (k = 0; k < gv_restore.length; k++) {
  209. gv_restore[k].outerHTML = gv_ignore_tag_map[i];
  210. }
  211. }
  212. for (i = 0; i < gv_ignore_class_len; i++) {
  213. gv_restore = document.querySelectorAll("[gv-ignore-val='gv-ignore-" + i + "']");
  214. for (k = 0; k < gv_restore.length; k++) {
  215. for (j in gv_ignore_class_map[i]) {
  216. gv_restore[k].setAttribute(j, gv_ignore_class_map[i][j]);
  217. }
  218. gv_restore[k].removeAttribute("gv-ignore-val");
  219. }
  220. }
  221. }
  222. };
  223. //自动替换事件属性,不成熟实用性不足,不启用
  224. var GoVueIgnoreOnEvent = function () {
  225. var all = document.querySelectorAll('*');
  226. all.forEach(function (el) {
  227. var len = el.attributes.length;
  228. var arr = [];
  229. var arr2 = [];
  230. for (var i = 0; i < len; i++) {
  231. var name = el.attributes.item(i).name;
  232. if (name[0] == "@" || name.indexOf("v-on:") == 0) {
  233. arr.push({
  234. name: name.replace("v-on:", "gv-on:").replace("@", "gv-on:"),
  235. value: el.attributes.item(i).value,
  236. });
  237. arr2.push({
  238. name: ":data-" + name.replace("v-on:", "gv-on:").replace("@", "gv-on:"),
  239. value: el.attributes.item(i).value.match(/\((.+?)\)/g),
  240. });
  241. // el.setAttribute("gv-on:" + name, el.attributes.item(i).value);
  242. // el.setAttribute(":gv-on-data:" + name, el.attributes.item(i).value.match(/\((.+?)\)/g));
  243. }
  244. }
  245. for (var i in arr) {
  246. console.log(JSON.stringify(arr[i]));
  247. el.setAttribute(arr[i].name, arr[i].value);
  248. el.setAttribute(arr2[i].name, arr2[i].value);
  249. }
  250. })
  251. };
  252. if (!HTMLDecode) {
  253. function HTMLDecode(text) {
  254. var temp = document.createElement("div");
  255. temp.innerHTML = text;
  256. var output = temp.innerText || temp.textContent;
  257. temp = null;
  258. return output;
  259. }
  260. }
  261. function GoVueRestoreRawTemplate() {
  262. var template = document.getElementsByTagName("gv-template-html");
  263. for (var i in template) {
  264. template[i].outerHTML = Base64Decode(template[i].innerHTML);
  265. }
  266. }