23 Commits

Author SHA1 Message Date
public_host 636d2f10c9 fix 4 years ago
public_host ce4f3eee63 fix 4 years ago
public_host 8564b74ec8 Merge remote-tracking branch 'origin/master' 4 years ago
public_host 96c6e7f780 fix 4 years ago
喵了个咪 79bc8a7fe9 fix 5 years ago
喵了个咪 927d0949e6 fix 5 years ago
喵了个咪 22e8aa2389 fix 5 years ago
3136352472 b3864e8ecd fix 5 years ago
3136352472 73bf82e3b5 fix 超时bug 5 years ago
3136352472 bb7faf28c8 fix 5 years ago
3136352472 4757a75ce1 去掉consile.log 5 years ago
3136352472 1229670576 fix 5 years ago
3136352472 28043bb6f5 fix 5 years ago
3136352472 57db461b85 fix 5 years ago
3136352472 a3e65c22c5 cache 5 years ago
3136352472 276db7e068 fix 5 years ago
3136352472 ee783db793 fix 5 years ago
3136352472 0a2a5b6441 文档更新 5 years ago
郑荣升 b58bceafb8 fix 5 years ago
郑荣升 99b3b051f5 fix 5 years ago
3136352472 bd9e32d90a fix 5 years ago
3136352472 50bced4fe4 fix 5 years ago
3136352472 3386e0cb49 fix 5 years ago
  1. 3
      .gitignore
  2. 6
      .idea/go-service-template.iml
  3. 723
      .idea/workspace.xml
  4. 90
      govue/bindata.go
  5. 34
      govue/cache.go
  6. 7
      govue/cmd/main.go
  7. 11
      govue/govue-js-src/build.js
  8. 1
      govue/govue-js-src/domino
  9. 9
      govue/govue-js-src/package.json
  10. 3
      govue/govue-js-src/predo.js
  11. 188
      govue/govue-js-src/src/index.js
  12. 47
      govue/govue-js-src/test.js
  13. 91033
      govue/govue-runtime/govue-dev.js
  14. 90923
      govue/govue-runtime/govue-release.js
  15. 82
      govue/govue-runtime/header.js
  16. 10
      govue/govue-runtime/runtime.js
  17. 8959
      govue/govue-runtime/vuessr.js
  18. 75
      govue/govue.go
  19. 327
      govue2/bindata.go
  20. 34
      govue2/cache.go
  21. 111
      govue2/cmd/main.go
  22. 57
      govue2/config.go
  23. 1
      govue2/govue-js-src/.gitignore
  24. 8
      govue2/govue-js-src/build.js
  25. 16
      govue2/govue-js-src/govue.js
  26. 40550
      govue2/govue-runtime/govue.js
  27. 176
      govue2/govue-runtime/header.js
  28. 7203
      govue2/govue-runtime/polyfill.js
  29. 43
      govue2/govue-runtime/runtime.js
  30. 211
      govue2/govue.go
  31. 58
      govue2/utils.go
  32. 51
      jsruntime/runtime.go
  33. 2
      jsruntime/timeout.go
  34. 7
      pool/pool.go
  35. 3
      readme.md
  36. 112
      static/index.html
  37. 41
      static/index.html.bak
  38. 6
      static/index.js
  39. 21
      static/js/govue.js
  40. 38
      static/router.html
  41. 12
      static/template/ssr.html
  42. 24
      static/use.js

3
.gitignore

@ -13,4 +13,5 @@
*.out *.out
.idea .idea
build build
*.json
*.json
node_modules

6
.idea/go-service-template.iml

@ -1,11 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" />
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/govue-js-src" />
<excludeFolder url="file://$MODULE_DIR$/govue/govue-js-src" />
</content>
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
</component> </component>

723
.idea/workspace.xml

@ -1,679 +1,140 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="BranchesTreeState">
<expand>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="LOCAL_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
</path>
<path>
<item name="ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="REMOTE_ROOT" type="e8cecc67:BranchNodeDescriptor" />
<item name="GROUP_NODE:origin" type="e8cecc67:BranchNodeDescriptor" />
</path>
</expand>
<select />
</component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="28e09409-bf4a-4792-a1b4-fc9301162fe5" name="Default Changelist" comment="fix">
<change afterPath="$PROJECT_DIR$/govue/config.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/govue/utils.go" afterDir="false" />
<change afterPath="$PROJECT_DIR$/readme.md" afterDir="false" />
<list default="true" id="1ed9cd54-bc74-41a2-84c0-b3db2772b1a0" name="Default Changelist" comment="fix">
<change afterPath="$PROJECT_DIR$/govue2/govue-js-src/.gitignore" afterDir="false" />
<change afterPath="$PROJECT_DIR$/govue2/govue-runtime/client.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.gitignore" beforeDir="false" afterPath="$PROJECT_DIR$/.gitignore" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/govue/bindata.go" beforeDir="false" afterPath="$PROJECT_DIR$/govue/bindata.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/govue/cmd/main.go" beforeDir="false" afterPath="$PROJECT_DIR$/govue/cmd/main.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/govue/govue-runtime/header.js" beforeDir="false" afterPath="$PROJECT_DIR$/govue/govue-runtime/header.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/govue/govue-runtime/runtime.js" beforeDir="false" afterPath="$PROJECT_DIR$/govue/govue-runtime/runtime.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/govue/govue.go" beforeDir="false" afterPath="$PROJECT_DIR$/govue/govue.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pool/pool.go" beforeDir="false" afterPath="$PROJECT_DIR$/pool/pool.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/static/css/main.css" beforeDir="false" afterPath="$PROJECT_DIR$/static/css/main.css" afterDir="false" />
<change beforePath="$PROJECT_DIR$/govue2/bindata.go" beforeDir="false" afterPath="$PROJECT_DIR$/govue2/bindata.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/govue2/govue-runtime/govue.js" beforeDir="false" afterPath="$PROJECT_DIR$/govue2/govue-runtime/govue.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/govue2/govue-runtime/header.js" beforeDir="false" afterPath="$PROJECT_DIR$/govue2/govue-runtime/header.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/govue2/govue-runtime/runtime.js" beforeDir="false" afterPath="$PROJECT_DIR$/govue2/govue-runtime/runtime.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/static/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/static/index.html" afterDir="false" /> <change beforePath="$PROJECT_DIR$/static/index.html" beforeDir="false" afterPath="$PROJECT_DIR$/static/index.html" afterDir="false" />
<change beforePath="$PROJECT_DIR$/static/use.js" beforeDir="false" afterPath="$PROJECT_DIR$/static/use.js" afterDir="false" />
<change beforePath="$PROJECT_DIR$/static/js/base64.js" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/static/js/govue.js" beforeDir="false" />
</list> </list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" /> <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" /> <option name="LAST_RESOLUTION" value="IGNORE" />
</component> </component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/static/use.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="418">
<caret line="22" column="46" selection-start-line="22" selection-start-column="46" selection-end-line="22" selection-end-column="46" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/static/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="266">
<caret line="17" column="42" selection-start-line="17" selection-start-column="33" selection-end-line="17" selection-end-column="42" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/govue/govue.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-489">
<caret line="92" column="10" selection-start-line="92" selection-start-column="10" selection-end-line="92" selection-end-column="10" />
<folding>
<element signature="e#67#362#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/.gitignore">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="247">
<caret line="13" column="5" selection-start-line="13" selection-start-column="5" selection-end-line="13" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/govue/cmd/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="57">
<caret line="26" column="31" selection-start-line="26" selection-start-column="27" selection-end-line="26" selection-end-column="31" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/readme.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="434">
<caret line="45" column="4" selection-start-line="45" selection-start-column="4" selection-end-line="45" selection-end-column="4" />
</first_editor>
<second_editor />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/govue/govue-runtime/runtime.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="304">
<caret line="19" column="20" selection-start-line="19" selection-start-column="14" selection-end-line="19" selection-end-column="20" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/govue/govue-runtime/header.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="254">
<caret line="112" column="9" selection-start-line="112" selection-start-column="9" selection-end-line="112" selection-end-column="9" />
<folding>
<element signature="e#337#1643#0" />
<element signature="e#365#1641#0" />
<element signature="e#689#715#0" />
<element signature="e#885#1189#0" />
<element signature="e#911#978#0" />
<element signature="e#1069#1129#0" />
<element signature="e#1256#1341#0" />
<element signature="e#1497#1544#0" />
<element signature="e#1562#1633#0" />
<element signature="n#!!doc;n#GetGoVueId#0" />
<element signature="e#1784#1867#0" />
<element signature="n#!!doc;n#RunInlineCode#0" />
<element signature="n#!!block;n#RunInlineCode#0" />
<element signature="e#2079#2889#0" />
<element signature="e#2233#2883#0" />
<element signature="e#2380#2430#0" />
<element signature="e#2491#2553#0" />
<element signature="e#2597#2656#0" />
<element signature="e#2688#2816#0" />
<element signature="e#2820#2873#0" />
<element signature="e#2923#3127#0" />
<element signature="e#2963#3029#0" />
<element signature="e#3067#3121#0" />
<element signature="n#!!doc;n#LoadGoParam#0" />
<element signature="e#3221#3238#0" />
<element signature="e#3269#5198#0" />
<element signature="e#3405#3428#0" />
<element signature="e#3459#4470#0" />
<element signature="e#3624#3778#0" />
<element signature="e#3964#4464#0" />
<element signature="e#4007#4067#0" />
<element signature="e#4226#4383#0" />
<element signature="e#4477#4506#0" />
<element signature="e#4538#5196#0" />
<element signature="e#4618#4835#0" />
<element signature="e#4746#4825#0" />
<element signature="e#4887#5190#0" />
<element signature="e#5017#5180#0" />
<element signature="e#5069#5166#0" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/../../../github.com/gin-gonic/gin/gin.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="183">
<caret line="295" column="22" selection-start-line="295" selection-start-column="22" selection-end-line="295" selection-end-column="22" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/govue/config.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="836">
<caret line="44" column="23" selection-start-line="44" selection-start-column="22" selection-end-line="44" selection-end-column="23" />
<folding>
<element signature="e#15#87#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl"> <component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES"> <option name="RECENT_TEMPLATES">
<list> <list>
<option value="HTML File" />
<option value="JavaScript File" /> <option value="JavaScript File" />
<option value="Go File" />
</list> </list>
</option> </option>
</component> </component>
<component name="FindInProjectRecents">
<findStrings>
<find>GoVueRequest</find>
<find>GoVueUse</find>
<find>暂不使用setTimeout</find>
<find>url.String()</find>
<find>loop.jobCount&quot;</find>
<find>loop.jobCount--</find>
<find>jobCount</find>
<find>Url</find>
<find>vue</find>
<find>jobCount--</find>
<find>GoUseRegisteredCall</find>
<find>GoUseCall</find>
<find>console</find>
<find>GoQuery</find>
<find>路由未找到</find>
<find>query</find>
<find>GoParam</find>
<find>RunString</find>
<find>Runs</find>
<find>timeo</find>
<find>dist</find>
<find>CreateFile</find>
<find>NotYetImplemented</find>
<find>v_ignore_class</find>
<find>govue-src</find>
<find>gv-common</find>
<find>hasaki</find>
<find>hsk</find>
<find>hskutils</find>
</findStrings>
</component>
<component name="GOROOT" path="C:\Go" /> <component name="GOROOT" path="C:\Go" />
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" /> <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component> </component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/govue-runtime/XMLHttpRequest.js" />
<option value="$PROJECT_DIR$/eventloop/eventloop.go" />
<option value="$PROJECT_DIR$/console/module.go" />
<option value="$PROJECT_DIR$/jsruntime/interval.go" />
<option value="$PROJECT_DIR$/jsruntime/console.go" />
<option value="$PROJECT_DIR$/jsruntime/go_request.go" />
<option value="$PROJECT_DIR$/jsruntime/use_callback.go" />
<option value="$PROJECT_DIR$/govue-runtime/runtime.js" />
<option value="$PROJECT_DIR$/jsruntime/timeout.go" />
<option value="$PROJECT_DIR$/govue-runtime/request.js" />
<option value="$PROJECT_DIR$/govue-runtime/header.js" />
<option value="$PROJECT_DIR$/../../../github.com/dop251/goja/runtime.go" />
<option value="$PROJECT_DIR$/jsruntime/runtime.go" />
<option value="$PROJECT_DIR$/main.go" />
<option value="$PROJECT_DIR$/govue/govue-runtime/govue.js" />
<option value="$PROJECT_DIR$/static/index.js" />
<option value="$PROJECT_DIR$/govue/govue-runtime/runtime.js" />
<option value="$PROJECT_DIR$/govue/govue-runtime/header.js" />
<option value="$PROJECT_DIR$/static/css/main.css" />
<option value="$PROJECT_DIR$/static/index.html" />
<option value="$PROJECT_DIR$/static/use.js" />
<option value="$PROJECT_DIR$/pool/pool.go" />
<option value="$PROJECT_DIR$/govue/utils.go" />
<option value="$PROJECT_DIR$/govue.json" />
<option value="$PROJECT_DIR$/govue/config.go" />
<option value="$PROJECT_DIR$/govue/cmd/main.go" />
<option value="$PROJECT_DIR$/readme.md" />
<option value="$PROJECT_DIR$/govue/govue.go" />
<option value="$PROJECT_DIR$/.gitignore" />
</list>
</option>
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="130" />
<option name="y" value="36" />
<option name="width" value="1710" />
<option name="height" value="967" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="go-service-template" type="b2602c69:ProjectViewProjectNode" />
<item name="go-service-template" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="go-service-template" type="b2602c69:ProjectViewProjectNode" />
<item name="go-service-template" type="462c0819:PsiDirectoryNode" />
<item name="govue" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="go-service-template" type="b2602c69:ProjectViewProjectNode" />
<item name="go-service-template" type="462c0819:PsiDirectoryNode" />
<item name="govue" type="462c0819:PsiDirectoryNode" />
<item name="cmd" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="go-service-template" type="b2602c69:ProjectViewProjectNode" />
<item name="go-service-template" type="462c0819:PsiDirectoryNode" />
<item name="govue" type="462c0819:PsiDirectoryNode" />
<item name="govue-runtime" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="go-service-template" type="b2602c69:ProjectViewProjectNode" />
<item name="go-service-template" type="462c0819:PsiDirectoryNode" />
<item name="static" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="go-service-template" type="b2602c69:ProjectViewProjectNode" />
<item name="go-service-template" type="462c0819:PsiDirectoryNode" />
<item name="static" type="462c0819:PsiDirectoryNode" />
<item name="css" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
<component name="ProjectId" id="1dJLbYMiy9MlHcALaEI4SeWe1wf" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
<property name="DefaultGoTemplateProperty" value="Go File" />
<property name="DefaultHtmlFileTemplate" value="HTML File" />
<property name="GO_FMT" value="true" /> <property name="GO_FMT" value="true" />
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="RunOnceActivity.ShowReadmeOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" /> <property name="WebServerToolWindowFactoryState" value="false" />
<property name="go.gopath.indexing.explicitly.defined" value="true" />
<property name="go.import.settings.migrated" value="true" /> <property name="go.import.settings.migrated" value="true" />
<property name="go.sdk.automatically.set" value="true" />
<property name="last_opened_file_path" value="$USER_HOME$" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/govue2/govue-js-src" />
<property name="nodejs_package_manager_path" value="npm" /> <property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="preferences.pluginManager" />
</component> </component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS"> <key name="CopyFile.RECENT_KEYS">
<recent name="C:\Users\wailo\go\src\git.ouxuan.net\3136352472\go-service-template\static\js" />
<recent name="C:\Users\wailo\go\src\git.ouxuan.net\3136352472\go-service-template\static" />
<recent name="C:\Users\wailo\go\src\git.ouxuan.net\3136352472\go-service-template\govue\govue-runtime" />
<recent name="C:\Users\wailo\go\src\git.ouxuan.net\3136352472\go-service-template\govue-runtime" />
<recent name="C:\Users\wailo\go\src\git.ouxuan.net\3136352472\go-service-template" />
<recent name="C:\Users\admin\go\src\git.ouxuan.net\3136352472\go-service-template\govue2\govue-js-src" />
<recent name="C:\Users\admin\go\src\git.ouxuan.net\3136352472\go-service-template\static" />
<recent name="C:\Users\admin\go\src\git.ouxuan.net\3136352472\go-service-template\govue2\govue-runtime" />
<recent name="C:\Users\admin\go\src\git.ouxuan.net\3136352472\go-service-template" />
</key> </key>
<key name="MoveFile.RECENT_KEYS">
<recent name="C:\Users\wailo\go\src\git.ouxuan.net\3136352472\go-service-template\static\js" />
<recent name="C:\Users\wailo\go\src\git.ouxuan.net\3136352472\go-service-template\govue" />
<recent name="C:\Users\wailo\go\src\git.ouxuan.net\3136352472\go-service-template" />
</key>
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component> </component>
<component name="RunManager"> <component name="RunManager">
<configuration name="govue" type="GoApplicationRunConfiguration" factoryName="Go Application">
<configuration name="go build git.ouxuan.net/3136352472/go-service-template/govue2/cmd" type="GoApplicationRunConfiguration" factoryName="Go Application" temporary="true" nameIsGenerated="true">
<module name="go-service-template" /> <module name="go-service-template" />
<working_directory value="$PROJECT_DIR$/" /> <working_directory value="$PROJECT_DIR$/" />
<go_parameters value="-i" />
<kind value="DIRECTORY" />
<filePath value="$PROJECT_DIR$/" />
<package value="git.ouxuan.net/3136352472/go-service-template" />
<directory value="C:\Users\admin\go\src\git.ouxuan.net\3136352472\go-service-template\govue\cmd" />
<output_directory value="$PROJECT_DIR$/" />
<kind value="PACKAGE" />
<filePath value="$PROJECT_DIR$/govue2/cmd/main.go" />
<package value="git.ouxuan.net/3136352472/go-service-template/govue2/cmd" />
<directory value="$PROJECT_DIR$/" />
<method v="2" /> <method v="2" />
</configuration> </configuration>
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info active="true" content_ui="combo" id="Project" order="0" visible="true" weight="0.36993605" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" sideWeight="0.49101797" visible="true" weight="0.2733189" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Docker" order="7" show_stripe_button="false" />
<window_info anchor="bottom" id="Database Changes" order="8" />
<window_info anchor="bottom" id="Version Control" order="9" sideWeight="0.499501" weight="0.32997987" />
<window_info anchor="bottom" id="Terminal" order="10" sideWeight="0.49151698" weight="0.3275488" />
<window_info anchor="bottom" id="Event Log" order="11" sideWeight="0.500499" side_tool="true" weight="0.32997987" />
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
<window_info anchor="right" id="Database" order="3" />
</layout>
<recent_temporary>
<list>
<item itemvalue="Go Build.go build git.ouxuan.net/3136352472/go-service-template/govue2/cmd" />
</list>
</recent_temporary>
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
<option name="version" value="2" />
</component>
<component name="Vcs.Log.Tabs.Properties">
<option name="TAB_STATES">
<map>
<entry key="MAIN">
<value>
<State />
</value>
</entry>
</map>
</option>
<option name="oldMeFiltersMigrated" value="true" />
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="fix" /> <MESSAGE value="fix" />
<option name="LAST_COMMIT_MESSAGE" value="fix" /> <option name="LAST_COMMIT_MESSAGE" value="fix" />
</component> </component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/../../../github.com/dop251/goja/object_gomap_reflect_test.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="346">
<caret line="91" column="55" selection-start-line="91" selection-start-column="28" selection-end-line="91" selection-end-column="55" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../../github.com/dop251/goja_nodejs/eventloop/eventloop.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="205">
<caret line="67" column="69" selection-start-line="67" selection-start-column="23" selection-end-line="67" selection-end-column="69" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/static/main.js" />
<entry file="file://$PROJECT_DIR$/eventloop/eventloop.go" />
<entry file="file://$PROJECT_DIR$/../../../github.com/dop251/goja_nodejs/require/module.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1736">
<caret line="43" column="19" selection-start-line="43" selection-start-column="19" selection-end-line="43" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/console/module.go" />
<entry file="file://$PROJECT_DIR$/../../hasaki-service/hasaki-sdk/hskhttpdo/httpdo.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="379">
<caret line="33" column="37" selection-start-line="33" selection-start-column="37" selection-end-line="33" selection-end-column="37" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../../github.com/gin-gonic/gin/context.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="188">
<caret line="45" column="14" selection-start-line="45" selection-start-column="14" selection-end-line="45" selection-end-column="27" />
</state>
</provider>
</entry>
<entry file="file://C:/Go/src/time/tick.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="169">
<caret line="10" column="20" selection-start-line="10" selection-start-column="20" selection-end-line="10" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/jsruntime/use_callback.go" />
<entry file="file://$PROJECT_DIR$/jsruntime/go_request.go" />
<entry file="file://$PROJECT_DIR$/jsruntime/interval.go" />
<entry file="file://$PROJECT_DIR$/jsruntime/console.go" />
<entry file="file://$PROJECT_DIR$/../../../github.com/wailovet/android-vrc/cmd/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="399">
<caret line="28" column="57" selection-start-line="28" selection-start-column="57" selection-end-line="28" selection-end-column="57" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../../github.com/elazarl/go-bindata-assetfs/assetfs.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="327">
<caret line="132" column="43" lean-forward="true" selection-start-line="132" selection-start-column="43" selection-end-line="132" selection-end-column="43" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/bindata.go" />
<entry file="file://C:/Go/src/net/http/fs.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="224">
<caret line="716" column="5" selection-start-line="716" selection-start-column="5" selection-end-line="716" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/jsruntime/timeout.go" />
<entry file="file://C:/Go/src/time/time.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="210">
<caret line="1163" column="24" selection-start-line="1163" selection-start-column="14" selection-end-line="1163" selection-end-column="24" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/govue-runtime/request.js" />
<entry file="file://$PROJECT_DIR$/govue/bindata.go" />
<entry file="file://$PROJECT_DIR$/jsruntime/runtime.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="3306">
<caret line="186" column="5" selection-start-line="186" selection-start-column="5" selection-end-line="186" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/main.go" />
<entry file="file://$PROJECT_DIR$/../../../github.com/jolestar/go-commons-pool/pool.go" />
<entry file="file://$PROJECT_DIR$/static/js/modernizr-3.8.0.min.js" />
<entry file="file://$PROJECT_DIR$/static/js/main.js" />
<entry file="file://$PROJECT_DIR$/static/js/jquery-3.4.1.min.js" />
<entry file="file://$PROJECT_DIR$/static/css/normalize.css" />
<entry file="file://$PROJECT_DIR$/../../../github.com/jolestar/go-commons-pool/config.go" />
<entry file="file://$PROJECT_DIR$/../../../github.com/dop251/goja/runtime.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="14934">
<caret line="802" column="36" selection-start-line="802" selection-start-column="36" selection-end-line="802" selection-end-column="36" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/static/js/vue.min.js" />
<entry file="file://$PROJECT_DIR$/govue/govue-runtime/govue.js" />
<entry file="file://$PROJECT_DIR$/../../../github.com/dop251/goja/parser/parser.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="2356">
<caret line="133" column="46" selection-start-line="133" selection-start-column="38" selection-end-line="133" selection-end-column="46" />
</state>
</provider>
</entry>
<entry file="file://$APPLICATION_HOME_DIR$/plugins/JavaScriptLanguage/jsLanguageServicesImpl/external/lib.dom.d.ts">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="19">
<caret line="4750" column="4" selection-start-line="4750" selection-start-column="4" selection-end-line="4750" selection-end-column="4" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/static/index.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="38">
<caret line="2" column="11" selection-start-line="2" selection-start-column="11" selection-end-line="3" selection-end-column="62" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/static/css/main.css">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="304">
<caret line="16" column="1" selection-start-line="16" selection-start-column="1" selection-end-line="16" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../hasaki-service/hasaki-sdk/hskutils/utils.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="156">
<caret line="32" selection-start-line="32" selection-end-line="42" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/pool/pool.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="209">
<caret line="17" column="34" selection-start-line="17" selection-start-column="34" selection-end-line="17" selection-end-column="34" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../updatemanage/helper/helper.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="156">
<caret line="50" selection-start-line="50" selection-end-line="54" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/govue.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="38">
<caret line="2" column="25" selection-start-line="2" selection-start-column="25" selection-end-line="2" selection-end-column="25" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/govue/utils.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="299">
<caret line="49" column="19" selection-start-line="49" selection-start-column="19" selection-end-line="49" selection-end-column="19" />
<folding>
<element signature="e#15#70#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/../../../github.com/gin-gonic/gin/gin.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="183">
<caret line="295" column="22" selection-start-line="295" selection-start-column="22" selection-end-line="295" selection-end-column="22" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/govue/cmd/main.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="57">
<caret line="26" column="31" selection-start-line="26" selection-start-column="27" selection-end-line="26" selection-end-column="31" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/govue/config.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="836">
<caret line="44" column="23" selection-start-line="44" selection-start-column="22" selection-end-line="44" selection-end-column="23" />
<folding>
<element signature="e#15#87#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/static/use.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="418">
<caret line="22" column="46" selection-start-line="22" selection-start-column="46" selection-end-line="22" selection-end-column="46" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/govue/govue-runtime/header.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="254">
<caret line="112" column="9" selection-start-line="112" selection-start-column="9" selection-end-line="112" selection-end-column="9" />
<folding>
<element signature="e#337#1643#0" />
<element signature="e#365#1641#0" />
<element signature="e#689#715#0" />
<element signature="e#885#1189#0" />
<element signature="e#911#978#0" />
<element signature="e#1069#1129#0" />
<element signature="e#1256#1341#0" />
<element signature="e#1497#1544#0" />
<element signature="e#1562#1633#0" />
<element signature="n#!!doc;n#GetGoVueId#0" />
<element signature="e#1784#1867#0" />
<element signature="n#!!doc;n#RunInlineCode#0" />
<element signature="n#!!block;n#RunInlineCode#0" />
<element signature="e#2079#2889#0" />
<element signature="e#2233#2883#0" />
<element signature="e#2380#2430#0" />
<element signature="e#2491#2553#0" />
<element signature="e#2597#2656#0" />
<element signature="e#2688#2816#0" />
<element signature="e#2820#2873#0" />
<element signature="e#2923#3127#0" />
<element signature="e#2963#3029#0" />
<element signature="e#3067#3121#0" />
<element signature="n#!!doc;n#LoadGoParam#0" />
<element signature="e#3221#3238#0" />
<element signature="e#3269#5198#0" />
<element signature="e#3405#3428#0" />
<element signature="e#3459#4470#0" />
<element signature="e#3624#3778#0" />
<element signature="e#3964#4464#0" />
<element signature="e#4007#4067#0" />
<element signature="e#4226#4383#0" />
<element signature="e#4477#4506#0" />
<element signature="e#4538#5196#0" />
<element signature="e#4618#4835#0" />
<element signature="e#4746#4825#0" />
<element signature="e#4887#5190#0" />
<element signature="e#5017#5180#0" />
<element signature="e#5069#5166#0" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/govue/govue-runtime/runtime.js">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="304">
<caret line="19" column="20" selection-start-line="19" selection-start-column="14" selection-end-line="19" selection-end-column="20" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/static/index.html">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="266">
<caret line="17" column="42" selection-start-line="17" selection-start-column="33" selection-end-line="17" selection-end-column="42" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/readme.md">
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
<state split_layout="SPLIT">
<first_editor relative-caret-position="434">
<caret line="45" column="4" selection-start-line="45" selection-start-column="4" selection-end-line="45" selection-end-column="4" />
</first_editor>
<second_editor />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/govue/govue.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-489">
<caret line="92" column="10" selection-start-line="92" selection-start-column="10" selection-end-line="92" selection-end-column="10" />
<folding>
<element signature="e#67#362#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/.gitignore">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="247">
<caret line="13" column="5" selection-start-line="13" selection-start-column="5" selection-end-line="13" selection-end-column="5" />
</state>
</provider>
</entry>
<component name="WindowStateProjectService">
<state x="401" y="468" key="#GOROOT" timestamp="1592138464823">
<screen x="0" y="0" width="1890" height="1024" />
</state>
<state x="401" y="468" key="#GOROOT/0.0.1890.1024@0.0.1890.1024" timestamp="1592138464823" />
<state width="1729" height="262" key="GridCell.Tab.0.bottom" timestamp="1592237447787">
<screen x="0" y="0" width="1890" height="1024" />
</state>
<state width="1729" height="262" key="GridCell.Tab.0.bottom/0.0.1890.1024@0.0.1890.1024" timestamp="1592237447787" />
<state width="1729" height="262" key="GridCell.Tab.0.center" timestamp="1592237447787">
<screen x="0" y="0" width="1890" height="1024" />
</state>
<state width="1729" height="262" key="GridCell.Tab.0.center/0.0.1890.1024@0.0.1890.1024" timestamp="1592237447787" />
<state width="1729" height="262" key="GridCell.Tab.0.left" timestamp="1592237447787">
<screen x="0" y="0" width="1890" height="1024" />
</state>
<state width="1729" height="262" key="GridCell.Tab.0.left/0.0.1890.1024@0.0.1890.1024" timestamp="1592237447787" />
<state width="1729" height="262" key="GridCell.Tab.0.right" timestamp="1592237447787">
<screen x="0" y="0" width="1890" height="1024" />
</state>
<state width="1729" height="262" key="GridCell.Tab.0.right/0.0.1890.1024@0.0.1890.1024" timestamp="1592237447787" />
<state x="370" y="243" key="Vcs.Push.Dialog.v2" timestamp="1592164477832">
<screen x="0" y="0" width="1890" height="1024" />
</state>
<state x="370" y="243" key="Vcs.Push.Dialog.v2/0.0.1890.1024@0.0.1890.1024" timestamp="1592164477832" />
<state x="477" y="243" width="599" height="534" key="find.popup" timestamp="1592161830863">
<screen x="0" y="0" width="1890" height="1024" />
</state>
<state x="477" y="243" width="599" height="534" key="find.popup/0.0.1890.1024@0.0.1890.1024" timestamp="1592161830863" />
</component> </component>
</project> </project>

90
govue/bindata.go
File diff suppressed because it is too large
View File

34
govue/cache.go

@ -0,0 +1,34 @@
package govue
import (
"sync"
"time"
)
var cache sync.Map
type mcache struct {
html string
creation int64
timeoutSec int64
}
func GetCache(key string) string {
v, _ := cache.Load(key)
if v != nil {
mc := v.(*mcache)
if time.Now().Unix() < mc.creation+mc.timeoutSec {
//log.Println("加载缓存")
return mc.html
}
}
return ""
}
func SetCache(key string, val string, timeoutSec int64) {
cache.Store(key, &mcache{
html: val,
creation: time.Now().Unix(),
timeoutSec: timeoutSec,
})
}

7
govue/cmd/main.go

@ -8,7 +8,6 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"log" "log"
"mime" "mime"
"net/http"
"path/filepath" "path/filepath"
) )
@ -69,13 +68,13 @@ func main() {
govue.SetPoolConfig(config.Pool) govue.SetPoolConfig(config.Pool)
gv, err := govue.NewGoVue(config.UseJsFile, config.StaticDir, mode == "debug")
gv, err := govue.NewGoVue(config.UseJsFile, config.StaticDir, config.Mode == "debug")
if errorPage404 != "" { if errorPage404 != "" {
config.ErrorPage404 = errorPage404 config.ErrorPage404 = errorPage404
} }
gv.SetErrorPage404(config.ErrorPage404) gv.SetErrorPage404(config.ErrorPage404)
gv.SetCacheSec(5)
if err != nil { if err != nil {
panic(err) panic(err)
} }
@ -92,7 +91,7 @@ func main() {
} }
if extData["cookie"].(map[string]string)["extdatasessionkey"] == "" { if extData["cookie"].(map[string]string)["extdatasessionkey"] == "" {
context.SetCookie("extdatasessionkey", uuid.Must(uuid.NewUUID()).String(), 0, "", context.Request.Host, http.SameSiteLaxMode, false, false)
context.SetCookie("extdatasessionkey", uuid.Must(uuid.NewUUID()).String(), 0, "", context.Request.Host, false, false)
} }
raw, err := gv.LoadStaticResources(context.Request, extData) raw, err := gv.LoadStaticResources(context.Request, extData)

11
govue/govue-js-src/build.js

@ -1,6 +1,11 @@
var fs = require("fs"); var fs = require("fs");
var envify = require('envify/custom') var envify = require('envify/custom')
var browserify = require("browserify"); var browserify = require("browserify");
browserify("./src/index.js").bundle().pipe(fs.createWriteStream("./dist/govue-dev.js"));
browserify("./src/index.js") browserify("./src/index.js")
// .transform("babelify", { // .transform("babelify", {
// plugins: [ // plugins: [
@ -11,13 +16,13 @@ browserify("./src/index.js")
// "transform-remove-strict-mode" // "transform-remove-strict-mode"
// ] // ]
// }) // })
.transform(
.transform(
// 用来处理 `node_modules` 文件 // 用来处理 `node_modules` 文件
{ global: true }, { global: true },
envify({ NODE_ENV: 'production' }) envify({ NODE_ENV: 'production' })
) )
.bundle() .bundle()
.pipe(fs.createWriteStream("./dist/index.js"));
.pipe(fs.createWriteStream("./dist/govue-release.js"));

1
govue/govue-js-src/domino

@ -0,0 +1 @@
Subproject commit e543301316335417ae43e5e645361fe2669fd05b

9
govue/govue-js-src/package.json

@ -15,13 +15,12 @@
"qs": "^6.9.4", "qs": "^6.9.4",
"through": "^2.3.8", "through": "^2.3.8",
"vue": "^2.6.11", "vue": "^2.6.11",
"vue-router": "^3.2.0"
"vue-hot-reload-api": "^2.3.4",
"vue-router": "^3.2.0",
"vue-server-renderer": "^2.6.11"
}, },
"scripts": { "scripts": {
"build": "node build.js && node predo.js && cp ./dist/index.js ../govue-runtime/govue.js"
},
"browser": {
"vue": "vue/dist/vue.common.js"
"build": "node build.js && node predo.js && cp ./dist/govue-release.js ../govue-runtime/govue-release.js && cp ./dist/govue-dev.js ../govue-runtime/govue-dev.js"
}, },
"devDependencies": { "devDependencies": {
"@babel/core": "^7.9.6", "@babel/core": "^7.9.6",

3
govue/govue-js-src/predo.js

@ -1,8 +1,9 @@
var fs = require("fs"); var fs = require("fs");
var content = fs.readFileSync("./dist/index.js")
var content = fs.readFileSync("./dist/govue-release.js")
// content = content.toString().replace(`_m("`, `this._m("`).replace(`var isHTMLTag = `, `var isHTMLTag = makeMap('html,body,base,head,link,meta,style,title');var _isHTMLTag = `) // content = content.toString().replace(`_m("`, `this._m("`).replace(`var isHTMLTag = `, `var isHTMLTag = makeMap('html,body,base,head,link,meta,style,title');var _isHTMLTag = `)
// content = content.toString().replace(`'production'`).replace(`"development"`)
// fs.writeFileSync("./dist/index.js", content) // fs.writeFileSync("./dist/index.js", content)

188
govue/govue-js-src/src/index.js

@ -1,22 +1,66 @@
process = require('process');
domino = require('../domino/lib/index'); domino = require('../domino/lib/index');
Node = require('../domino/lib/index');
// domino = require('domino');
window = domino.createWindow("", "http://127.0.0.1/"); window = domino.createWindow("", "http://127.0.0.1/");
document = window.document; document = window.document;
location = window.location; location = window.location;
Intl = require('./Intl'); Intl = require('./Intl');
Vue = require('vue');
Promise = require('es6-promise').Promise;
if (process.env.NODE_ENV == "production") {
Vue = require('../node_modules/vue/dist/vue.min');
} else {
Vue = require('../node_modules/vue/dist/vue');
}
Vue.config.ignoredElements = [/^b-/, /^gv-/];
Vue.GoVueExtend = Vue.extend;
Vue.UseRaw = function () {
Vue.use_raw = true
return Vue
};
function HTMLEncode(html) {
var temp = document.createElement("div");
(temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html);
var output = temp.innerHTML;
temp = null;
return output;
}
function Base64Encode(html) {
return new Buffer(html).toString('base64');
}
Vue.extend = function (a, b) {
if (Vue.use_raw) {
var template = Base64Encode(a.template)
a.template = "<gv-template-html>" + template + "</gv-template-html>"
Vue.use_raw = false;
}
return Vue.GoVueExtend(a, b)
}
vuessr = require('vue-server-renderer')
VueRouter = require('vue-router');
vuessr = require('vue-server-renderer')
VueRouter = require('vue-router');
Vue.use(VueRouter) Vue.use(VueRouter)
$ = jQuery = require('jquery'); $ = jQuery = require('jquery');
require('jquery-bbq'); require('jquery-bbq');
qs = require('qs'); qs = require('qs');
Promise = require('es6-promise').Promise;
axios = require('axios'); axios = require('axios');
@ -27,93 +71,93 @@ var settle = require('axios/lib/core/settle');
var createError = require('axios/lib/core/createError'); var createError = require('axios/lib/core/createError');
function transformResponse(mpResponse, config, mpRequestOption) { function transformResponse(mpResponse, config, mpRequestOption) {
var headers = mpResponse.header || mpResponse.headers;
var status = mpResponse.statusCode || mpResponse.status;
var statusText = '';
if (status === 200) {
statusText = 'OK';
}
else if (status === 400) {
statusText = 'Bad Request';
}
var response = {
data: mpResponse.data,
status: status,
statusText: statusText,
headers: headers,
config: config,
request: mpRequestOption
};
return response;
var headers = mpResponse.header || mpResponse.headers;
var status = mpResponse.statusCode || mpResponse.status;
var statusText = '';
if (status === 200) {
statusText = 'OK';
}
else if (status === 400) {
statusText = 'Bad Request';
}
var response = {
data: mpResponse.data,
status: status,
statusText: statusText,
headers: headers,
config: config,
request: mpRequestOption
};
return response;
} }
axios.defaults.adapter = function (config) { axios.defaults.adapter = function (config) {
return new Promise(function (resolve, reject) {
// console.log("resolve", JSON.stringify(resolve));
// console.log("reject", JSON.stringify(reject));
// console.log("config", JSON.stringify(config));
// console.log("axios.defaults.headers", JSON.stringify(axios.defaults.headers));
var mpRequestOption = {
url: buildURL(buildFullPath(config.baseURL, config.url), config.params, config.paramsSerializer),
method: config["method"].toUpperCase(),
data: config["data"],
header: config["headers"],
timeout: config["timeout"],
success: function (mpResponse) {
// console.log("success");
// console.log(JSON.stringify(mpResponse));
var response = transformResponse(mpResponse, config, mpRequestOption);
settle(resolve, reject, response);
},
fail: function (error) {
reject(createError(error.data));
},
};
net.request(mpRequestOption)
})
return new Promise(function (resolve, reject) {
// console.log("resolve", JSON.stringify(resolve));
// console.log("reject", JSON.stringify(reject));
// console.log("config", JSON.stringify(config));
// console.log("axios.defaults.headers", JSON.stringify(axios.defaults.headers));
var mpRequestOption = {
url: buildURL(buildFullPath(config.baseURL, config.url), config.params, config.paramsSerializer),
method: config["method"] ? config["method"].toUpperCase() : "get",
data: config["data"],
header: config["headers"],
timeout: config["timeout"],
success: function (mpResponse) {
// console.log("success");
// console.log(JSON.stringify(mpResponse));
var response = transformResponse(mpResponse, config, mpRequestOption);
settle(resolve, reject, response);
},
fail: function (error) {
reject(createError(error.data));
},
};
net.request(mpRequestOption)
})
}; };
useRoute = {}; useRoute = {};
GoUseRegistered = function (id, cb) { GoUseRegistered = function (id, cb) {
useRoute[id] = cb
useRoute[id] = cb
}; };
goUseCallCache goUseCallCache
GoUseCall = function (e) { GoUseCall = function (e) {
// console.log("GoUseCall", 1)
if (goUseCallCache) {
goUseCallCache(e)
}
// console.log("GoUseCall", 2)
var id = e["id"];
var path = e["path"];
var query = e["query"];
if (useRoute[id]) {
// console.log(useRoute[id])
useRoute[id](query);
return
}
// console.log("GoUseCall", 3)
if (useRoute[path]) {
useRoute[path](query);
return
}
// console.log("路由未找到:", id, "-", path)
// console.log("GoUseCall", 1)
if (goUseCallCache) {
goUseCallCache(e)
}
// console.log("GoUseCall", 2)
var id = e["id"];
var path = e["path"];
var query = e["query"];
if (useRoute[id]) {
// console.log(useRoute[id])
useRoute[id](query);
return
}
// console.log("GoUseCall", 3)
if (useRoute[path]) {
useRoute[path](query);
return
}
// console.log("路由未找到:", id, "-", path)
} }
GoUse = function (cb) { GoUse = function (cb) {
goUseCallCache = cb
goUseCallCache = cb
} }
for (var i in global) { for (var i in global) {
window[i] = global[i]
window[i] = global[i]
} }

47
govue/govue-js-src/test.js

@ -1,47 +0,0 @@
global.domino = null
global.window = null
global.document = null
global.location = null
global.Vue = null
global.VueRouter = null
global.axios = null
navigator = null
require("./dist/index")
var html = "<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <title>Title</title>\n</head>\n<body>\n<div id=\"classifyer\">\n code : {{code}}\n <li v-for=\"todo in data\">\n classifyer_id :{{ todo.classifyer_id }}\n name :{{ todo.name }}\n </li>\n</div>\n</body>\n</html>"
window = domino.createWindow(html, "http://127.0.0.1/#/detail/?id=123");
document = window.document;
location = window.location;
var vue = new Vue({
el: "#classifyer",
data: function(){
return {
code: 212123213123,
data: [
{ name: "1asdasdasd23" }
]
}
}
});
console.log(document.innerHTML);
Vue.axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
// always executed
});

91033
govue/govue-runtime/govue-dev.js
File diff suppressed because it is too large
View File

90923
govue/govue-runtime/govue-release.js
File diff suppressed because it is too large
View File

82
govue/govue-runtime/header.js

@ -1,12 +1,18 @@
var domino, window, document, location, Vue, VueRouter, vuessr, navigator, axios, Promise, GoUseCall, GoUse, var domino, window, document, location, Vue, VueRouter, vuessr, navigator, axios, Promise, GoUseCall, GoUse,
GoUseRegistered, GoUseRegistered,
govueId, useRoute, goUseCallCache, $, jQuery, GoParam, qs, Intl;
govueId, useRoute, goUseCallCache, $, jQuery, GoParam, qs, Intl, process, Node;
var global = this; var global = this;
global.Vue = Vue; global.Vue = Vue;
global.VueRouter = VueRouter; global.VueRouter = VueRouter;
global.Intl = Intl; global.Intl = Intl;
global.process = process;
global.Node = Node;
process = {
env: {
VUE_ENV: "server",
NODE_ENV: "production"
}
};
navigator = { 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 " userAgent: "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 a/537.36 "
}; };
@ -64,7 +70,6 @@ var net = {
timeout: timeout timeout: timeout
}); });
resp = JSON.parse(resp); resp = JSON.parse(resp);
var statusCode = resp["statusCode"]; var statusCode = resp["statusCode"];
var result = resp["data"]; var result = resp["data"];
@ -76,19 +81,19 @@ var net = {
if (statusCode == 200) { if (statusCode == 200) {
success && success({ success && success({
data: result, data: result,
statusCode: statusCode,
statusCode: statusCode + "",
}); });
} else { } else {
fail && fail({ fail && fail({
data: result, data: result,
statusCode: statusCode,
statusCode: statusCode + "",
}) })
} }
complete && complete({
data: result,
statusCode: statusCode,
})
// complete && complete({
// data: result,
// statusCode: statusCode + "",
// })
} }
}; };
@ -96,6 +101,10 @@ var net = {
function GoVueRender(template, app, context) { function GoVueRender(template, app, context) {
var raw = GoReadFile(template); var raw = GoReadFile(template);
// console.log(vuessr);
var renderer = vuessr.createRenderer({ var renderer = vuessr.createRenderer({
template: raw template: raw
}); });
@ -126,7 +135,12 @@ function LoadPage(src, href) {
* @return {string} * @return {string}
*/ */
function GetGoVueId() { function GetGoVueId() {
return document.querySelector("[gv-id]").getAttribute("gv-id");
var h = document.querySelector("[gv-id]")
var id = "";
if (h) {
id = h.getAttribute("gv-id");
}
return id;
} }
/** /**
@ -137,7 +151,7 @@ function RunInlineCode() {
var jsInlineFiles = []; var jsInlineFiles = [];
for (var i = jsInline.length - 1; i >= 0; i--) { for (var i = jsInline.length - 1; i >= 0; i--) {
var isGoVueSrc = jsInline[i].hasAttribute("gv-src"); var isGoVueSrc = jsInline[i].hasAttribute("gv-src");
var isGoVueCommon = jsInline[i].hasAttribute("gv-common");
var isGoVuePrivate = jsInline[i].hasAttribute("gv-private");
if (isGoVueSrc) { if (isGoVueSrc) {
var res = {}; var res = {};
var file = jsInline[i].getAttribute("src"); var file = jsInline[i].getAttribute("src");
@ -151,11 +165,10 @@ function RunInlineCode() {
jsInlineFiles.unshift(res); jsInlineFiles.unshift(res);
} }
if (isGoVueCommon) {
jsInline[i].removeAttribute("gv-src");
jsInline[i].removeAttribute("gv-common");
} else {
if (isGoVuePrivate) {
jsInline[i].remove(); jsInline[i].remove();
} else {
jsInline[i].removeAttribute("gv-src");
} }
} }
} }
@ -194,6 +207,12 @@ var GoVueIgnore = function () {
* 忽略前置 * 忽略前置
*/ */
this.ignore = function () { 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"); var gv_ignore = document.getElementsByTagName("gv-ignore");
gv_ignore_len = gv_ignore.length; gv_ignore_len = gv_ignore.length;
for (var i = gv_ignore_len - 1; i >= 0; i--) { for (var i = gv_ignore_len - 1; i >= 0; i--) {
@ -202,7 +221,8 @@ var GoVueIgnore = function () {
} }
var gv_ignore_class = document.querySelectorAll("[gv-ignore]"); var gv_ignore_class = document.querySelectorAll("[gv-ignore]");
gv_ignore_class_len = gv_ignore_class.length; gv_ignore_class_len = gv_ignore_class.length;
// console.log("gv_ignore_class_len",gv_ignore_class_len)
// console.log(document.innerHTML);
// console.log("gv_ignore_class_len",gv_ignore_class_len)
for (var i = 0; i < gv_ignore_class_len; i++) { for (var i = 0; i < gv_ignore_class_len; i++) {
if (!gv_ignore_class_map[i]) { if (!gv_ignore_class_map[i]) {
gv_ignore_class_map[i] = {}; gv_ignore_class_map[i] = {};
@ -219,6 +239,14 @@ var GoVueIgnore = function () {
gv_ignore_class[i].removeAttribute("gv-ignore"); gv_ignore_class[i].removeAttribute("gv-ignore");
gv_ignore_class[i].setAttribute("gv-ignore-val", "gv-ignore-" + i) 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>")
}
}; };
/** /**
@ -277,4 +305,22 @@ var GoVueIgnoreOnEvent = function () {
} }
}) })
};
};
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);
}
}

10
govue/govue-runtime/runtime.js

@ -1,5 +1,6 @@
if (!IS_VUE_SSR) { if (!IS_VUE_SSR) {
Vue.GV = true;
try { try {
LoadPage(GoHtmlSrc, GoHref); LoadPage(GoHtmlSrc, GoHref);
} catch (e) { } catch (e) {
@ -20,7 +21,7 @@ if (!IS_VUE_SSR) {
var goVueIgnore = new GoVueIgnore(); var goVueIgnore = new GoVueIgnore();
goVueIgnore.ignore(); goVueIgnore.ignore();
// console.log(document.innerHTML);
} catch (e) { } catch (e) {
console.log("goVueIgnore.ignore:" + e); console.log("goVueIgnore.ignore:" + e);
} }
@ -49,6 +50,13 @@ if (!IS_VUE_SSR) {
} }
try { try {
GoVueRestoreRawTemplate();
} catch (e) {
console.log("GoVueRestoreRawTemplate:" + e);
}
try {
GoReturn(document.innerHTML); GoReturn(document.innerHTML);
} catch (e) { } catch (e) {
console.log("GoReturn:" + e) console.log("GoReturn:" + e)

8959
govue/govue-runtime/vuessr.js
File diff suppressed because it is too large
View File

75
govue/govue.go

@ -21,13 +21,16 @@ type GoVue struct {
UseJsPath string UseJsPath string
ErrorPage404 string ErrorPage404 string
Resources *assetfs.AssetFS Resources *assetfs.AssetFS
IsDebugMode bool
jsRuntimePool *pool.JsRuntimePool jsRuntimePool *pool.JsRuntimePool
CacheSec int64
} }
func NewGoVueDefaultConfig(debug bool) (gv *GoVue, err error) { func NewGoVueDefaultConfig(debug bool) (gv *GoVue, err error) {
gv = &GoVue{ gv = &GoVue{
Resources: assetFS(),
Resources: assetFS(),
IsDebugMode: debug,
} }
err = gv.initRender(debug) err = gv.initRender(debug)
return return
@ -35,14 +38,19 @@ func NewGoVueDefaultConfig(debug bool) (gv *GoVue, err error) {
func NewGoVue(useJsPath string, staticPath string, debug bool) (gv *GoVue, err error) { func NewGoVue(useJsPath string, staticPath string, debug bool) (gv *GoVue, err error) {
gv = &GoVue{ gv = &GoVue{
StaticPath: staticPath,
UseJsPath: useJsPath,
Resources: assetFS(),
StaticPath: staticPath,
UseJsPath: useJsPath,
Resources: assetFS(),
IsDebugMode: debug,
} }
err = gv.initRender(debug) err = gv.initRender(debug)
return return
} }
func (gv *GoVue) SetCacheSec(cacheSec int64) {
gv.CacheSec = cacheSec
}
func (gv *GoVue) SetErrorPage404(page string) { func (gv *GoVue) SetErrorPage404(page string) {
gv.ErrorPage404 = page gv.ErrorPage404 = page
} }
@ -59,51 +67,47 @@ func (gv *GoVue) initRender(debug bool) (err error) {
if gv.UseJsPath == "" { if gv.UseJsPath == "" {
gv.UseJsPath = filepath.Join(gv.StaticPath, "use.js") gv.UseJsPath = filepath.Join(gv.StaticPath, "use.js")
} }
govueScriptFile := "govue-release.js"
if gv.IsDebugMode {
govueScriptFile = "govue-dev.js"
}
//vuessr, err := ioutil.ReadFile(filepath.Join("govue", "govue-runtime", "vuessr.js"))
//if err != nil {
// return
//}
//polyfill, err := ioutil.ReadFile(filepath.Join("govue", "govue-runtime", "polyfill.js")) //polyfill, err := ioutil.ReadFile(filepath.Join("govue", "govue-runtime", "polyfill.js"))
//if err != nil { //if err != nil {
// return // return
//} //}
// //
//mainScript, err := ioutil.ReadFile(filepath.Join("govue", "govue-runtime", "runtime.js"))
//headerScript, err := ioutil.ReadFile(filepath.Join("govue", "govue-runtime", "header.js"))
//if err != nil { //if err != nil {
// return // return
//} //}
// //
//headerScript, err := ioutil.ReadFile(filepath.Join("govue", "govue-runtime", "header.js"))
//govueScript, err := ioutil.ReadFile(filepath.Join("govue", "govue-runtime", govueScriptFile))
//if err != nil { //if err != nil {
// return // return
//} //}
// //
//govueScript, err := ioutil.ReadFile(filepath.Join("govue", "govue-js-src", "dist", "index.js"))
//mainScript, err := ioutil.ReadFile(filepath.Join("govue", "govue-runtime", "runtime.js"))
//if err != nil { //if err != nil {
// return // return
//} //}
vuessr, err := gv.Resources.Asset(filepath.Join("govue-runtime", "vuessr.js"))
if err != nil {
return
}
polyfill, err := gv.Resources.Asset(filepath.Join("govue-runtime", "polyfill.js")) polyfill, err := gv.Resources.Asset(filepath.Join("govue-runtime", "polyfill.js"))
if err != nil { if err != nil {
return return
} }
mainScript, err := gv.Resources.Asset(filepath.Join("govue-runtime", "runtime.js"))
headerScript, err := gv.Resources.Asset(filepath.Join("govue-runtime", "header.js"))
if err != nil { if err != nil {
return return
} }
govueScript, err := gv.Resources.Asset(filepath.Join("govue-runtime", "govue.js"))
govueScript, err := gv.Resources.Asset(filepath.Join("govue-runtime", govueScriptFile))
if err != nil { if err != nil {
return return
} }
headerScript, err := gv.Resources.Asset(filepath.Join("govue-runtime", "header.js"))
mainScript, err := gv.Resources.Asset(filepath.Join("govue-runtime", "runtime.js"))
if err != nil { if err != nil {
return return
} }
@ -116,9 +120,6 @@ func (gv *GoVue) initRender(debug bool) (err error) {
Src: string(headerScript), Src: string(headerScript),
}, },
jsruntime.Rely{ jsruntime.Rely{
Src: string(vuessr),
},
jsruntime.Rely{
Src: string(govueScript), Src: string(govueScript),
}, },
}, jsruntime.ModeSync, debug) }, jsruntime.ModeSync, debug)
@ -150,6 +151,16 @@ func (gv *GoVue) StartPoolLog() {
} }
func (gv *GoVue) LoadStaticResources(request *http.Request, goExtDataS ...interface{}) (result []byte, err error) { func (gv *GoVue) LoadStaticResources(request *http.Request, goExtDataS ...interface{}) (result []byte, err error) {
cacheKey := fmt.Sprintf("%s|%s", request.URL.Path, request.URL.RawQuery)
if gv.CacheSec > 0 {
html := GetCache(cacheKey)
if html != "" {
//log.Println("加载缓存")
return []byte(html), nil
}
}
//log.Println("非缓存", cacheKey)
var staticDir string var staticDir string
var filePath = request.URL.Path var filePath = request.URL.Path
@ -187,9 +198,20 @@ func (gv *GoVue) LoadStaticResources(request *http.Request, goExtDataS ...interf
} }
result, err = ioutil.ReadFile(filePath) result, err = ioutil.ReadFile(filePath)
if err != nil {
return gv.renderErrPage(404, request, goExtDataS...)
govueDebug := request.URL.Query().Get("govue_debug")
if govueDebug == "1" {
return
} }
if err != nil {
result, err = gv.renderErrPage(404, request, goExtDataS...)
if gv.CacheSec > 0 {
SetCache(cacheKey, string(result), gv.CacheSec)
}
return
} //
if filepath.Ext(filePath) != ".html" && filepath.Ext(filePath) != ".vue" { if filepath.Ext(filePath) != ".html" && filepath.Ext(filePath) != ".vue" {
return return
} }
@ -204,9 +226,16 @@ func (gv *GoVue) LoadStaticResources(request *http.Request, goExtDataS ...interf
} else { } else {
jr.SetVariable("IS_VUE_SSR", false) jr.SetVariable("IS_VUE_SSR", false)
} }
err = jr.Render(filePath, fmt.Sprintf("http://%s%s", request.Host, request.RequestURI), string(result), goExtData, func(data string) { err = jr.Render(filePath, fmt.Sprintf("http://%s%s", request.Host, request.RequestURI), string(result), goExtData, func(data string) {
result = []byte(data) result = []byte(data)
if gv.CacheSec > 0 {
SetCache(cacheKey, string(result), gv.CacheSec)
}
}) })
if err != nil {
result = []byte(err.Error())
}
}) })
return return

327
govue2/bindata.go
File diff suppressed because it is too large
View File

34
govue2/cache.go

@ -0,0 +1,34 @@
package govue2
import (
"sync"
"time"
)
var cache sync.Map
type mcache struct {
html string
creation int64
timeoutSec int64
}
func GetCache(key string) string {
v, _ := cache.Load(key)
if v != nil {
mc := v.(*mcache)
if time.Now().Unix() < mc.creation+mc.timeoutSec {
//log.Println("加载缓存")
return mc.html
}
}
return ""
}
func SetCache(key string, val string, timeoutSec int64) {
cache.Store(key, &mcache{
html: val,
creation: time.Now().Unix(),
timeoutSec: timeoutSec,
})
}

111
govue2/cmd/main.go

@ -0,0 +1,111 @@
package main
import (
"flag"
"fmt"
govue "git.ouxuan.net/3136352472/go-service-template/govue2"
"github.com/gin-gonic/gin"
"log"
"mime"
"path/filepath"
)
func main() {
var addr string
var static string
var useFile string
var mode string
var path string
var errorPage404 string
flag.StringVar(&path, "config", "govue.json", "配置文件路径")
flag.StringVar(&static, "static", "", "静态文件目录")
flag.StringVar(&addr, "addr", "", "监听ip:port")
flag.StringVar(&mode, "mode", "", "模式release/debug")
flag.StringVar(&errorPage404, "error_page_404", "", "404错误页面路径")
flag.Parse()
if flag.Arg(0) == "init" {
err := govue.GenerateConfig(path)
if err != nil {
fmt.Print("文件:", path, "\n生成失败:", err)
} else {
abs, _ := filepath.Abs(path)
fmt.Print("文件:", abs, "\n生成成功:")
}
return
}
config, err := govue.GetConfig(path)
fmt.Println("配置载入:", path)
fmt.Println("渲染协程池最大总数:", config.Pool.MaxTotal)
fmt.Println("渲染协程池最大空闲数:", config.Pool.MaxIdle)
fmt.Println("渲染协程池最小空闲数:", config.Pool.MinIdle)
if addr != "" {
config.Addr = addr
}
if static != "" {
config.StaticDir = static
}
if useFile != "" {
config.UseJsFile = useFile
}
if mode != "" {
config.Mode = mode
}
gin.SetMode(config.Mode)
r := gin.Default()
govue.SetPoolConfig(config.Pool)
gv, err := govue.NewGoVue(config.UseJsFile, config.StaticDir, config.Mode == "debug")
if errorPage404 != "" {
config.ErrorPage404 = errorPage404
}
gv.SetErrorPage404(config.ErrorPage404)
gv.SetCacheSec(5)
if err != nil {
panic(err)
}
r.NoRoute(func(context *gin.Context) {
raw, err := gv.LoadStaticResources(context.Request)
if err != nil {
_, _ = context.Writer.Write(raw)
return
}
mime.TypeByExtension(filepath.Ext(context.Request.URL.Path))
ext := filepath.Ext(context.Request.URL.Path)
if ext == "" {
ext = ".html"
}
context.Writer.Header().Set("Content-Type", mime.TypeByExtension(ext)+"; charset=utf-8")
context.Writer.WriteHeader(200)
_, _ = context.Writer.Write(raw)
})
r.Use(func(context *gin.Context) {
context.Header("Access-Control-Allow-Origin", "*")
context.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
context.Header("Access-Control-Allow-Headers", "Action, Module, X-PINGOTHER, Content-Type, Content-Disposition")
})
gv.StartPoolLog()
for {
err = r.Run(config.Addr)
if err != nil {
log.Println("服务意外停止:", err)
}
}
}

57
govue2/config.go

@ -0,0 +1,57 @@
package govue2
import (
"errors"
"git.ouxuan.net/3136352472/go-service-template/pool"
)
type Config struct {
Addr string `json:"addr"`
StaticDir string `json:"static_dir"`
UseJsFile string `json:"use_js_file"`
ErrorPage404 string `json:"error_page_404"`
Mode string `json:"mode"`
Pool pool.Config `json:"pool"`
}
func GenerateConfig(path string) (err error) {
if pathExists(path) {
err = errors.New("配置文件已存在")
return
}
config := Config{
Addr: "0.0.0.0:8080",
StaticDir: "static",
UseJsFile: "static/use.js",
Mode: "release",
Pool: pool.Config{
MaxIdle: 2000,
MinIdle: 5,
MaxTotal: 6000,
},
}
jsonToFile(path, config)
return
}
func GetConfig(path string) (c *Config, err error) {
c = &Config{
Addr: "0.0.0.0:8080",
StaticDir: "static",
UseJsFile: "static/use.js",
Mode: "release",
Pool: pool.Config{
MaxIdle: 2000,
MinIdle: 5,
MaxTotal: 6000,
},
}
if pathExists(path) {
jsonByFile(path, c)
}
return
}

1
govue2/govue-js-src/.gitignore

@ -0,0 +1 @@
node_modules

8
govue2/govue-js-src/build.js

@ -0,0 +1,8 @@
var fs = require("fs");
var envify = require('envify/custom')
var browserify = require("browserify");
browserify("./govue.js")
.transform({ global: true }, envify({ NODE_ENV: 'production' }))
.bundle()
.pipe(fs.createWriteStream("../govue-runtime/govue.js"));

16
govue2/govue-js-src/govue.js

@ -0,0 +1,16 @@
var process = { env: { VUE_ENV: "server", NODE_ENV: "production" } }; this.global = { process: process };
Promise = require('es6-promise').Promise;
require('Vue');
require('vue-router')
require('vue-server-renderer')
require('axios');
require('qs');
require('axios/lib/helpers/buildURL');
require('axios/lib/core/buildFullPath');
require('axios/lib/core/settle');
require('axios/lib/core/createError');
require("htmlparser2");
GV.init = function(cb){
cb(require)
}

40550
govue2/govue-runtime/govue.js
File diff suppressed because it is too large
View File

176
govue2/govue-runtime/header.js

@ -0,0 +1,176 @@
var GV = {};
var isBrowser = false;
var Promise;
var GoUseCallback;
var GoUse = function (cb) {
GoUseCallback = "with(this){(" + cb.toString() + ")()}";
}
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 + "",
})
}
}
};
var axiosUse = function (ctx) {
var buildURL = ctx.require('axios/lib/helpers/buildURL');
var buildFullPath = ctx.require('axios/lib/core/buildFullPath');
var settle = ctx.require('axios/lib/core/settle');
var createError = ctx.require('axios/lib/core/createError');
function transformResponse(mpResponse, config, mpRequestOption) {
var headers = mpResponse.header || mpResponse.headers;
var status = mpResponse.statusCode || mpResponse.status;
var statusText = '';
if (status === 200) {
statusText = 'OK';
} else if (status === 400) {
statusText = 'Bad Request';
}
var response = {
data: mpResponse.data,
status: status,
statusText: statusText,
headers: headers,
config: config,
request: mpRequestOption
};
return response;
}
ctx.axios.defaults.adapter = function (config) {
return new Promise(function (resolve, reject) {
var mpRequestOption = {
url: buildURL(buildFullPath(config.baseURL, config.url), config.params, config.paramsSerializer),
method: config["method"] ? config["method"].toUpperCase() : "get",
data: config["data"],
header: config["headers"],
timeout: config["timeout"],
success: function (mpResponse) {
var response = transformResponse(mpResponse, config, mpRequestOption);
settle(resolve, reject, response);
},
fail: function (error) {
reject(createError(error.data));
},
};
net.request(mpRequestOption)
})
};
}
var GetGoVueTemplate = function (raw) {
var tagStart = "<!--gv-start-->";
var tagEnd = "<!--gv-end-->";
var start = raw.indexOf(tagStart)
if (start < 0) {
return
}
var end = raw.indexOf(tagEnd)
if (end < 0) {
throw "注释未闭合"
return
}
var content = raw.substring(start + tagStart.length, end);
var template = raw.substring(0, start) + "<!--vue-ssr-outlet-->\n{{{GoVueTemplate}}}\n{{{GoVueData}}}" + raw.substr(end + tagEnd.length);
return {
template: template,
content: content,
}
}
var GetGoVueJsCode = function (htmlparser2, raw) {
var codes = [];
var flag = false;
var parser = new htmlparser2.Parser(
{
onopentag: function (name, attribs) {
flag = (name === "script" && (attribs["gv-src"] || attribs["gv-src"] === ""))
if (flag) {
if (attribs.src) {
codes.push(GoReadFile(attribs.src))
}
}
// console.log("name", name, attribs["gv-src"]);
},
ontext: function (text) {
if (flag && text && text !== "") {
codes.push(text)
}
// console.log("-->", text);
},
},
{decodeEntities: true}
);
parser.write(raw)
parser.end();
return codes;
}

7203
govue2/govue-runtime/polyfill.js
File diff suppressed because it is too large
View File

43
govue2/govue-runtime/runtime.js

@ -0,0 +1,43 @@
GV.init(function (_require) {
new (function () {
this.require = _require;
this.Vue = _require('Vue');
this.VueRouter = _require('vue-router');
this.Vue.use(this.VueRouter)
this.axios = _require('axios');
var htmlparser2 = _require('htmlparser2');
axiosUse(this);
this.qs = _require('qs');
this.GoVueMount = function (app, context) {
var ctx = GetGoVueTemplate(GoHtmlSrc)
app.$options.template = ctx.content;
// console.log(ctx.template)
var renderer = _require('vue-server-renderer').createRenderer({
template: ctx.template
})
if(!context){
context = {}
}
context.GoVueTemplate = "<go-vue-template style='display: none'>" + Base64Encode(encodeURIComponent(ctx.content)) + "</go-vue-template>"
context.GoVueData = "<go-vue-data style='display: none'>" + Base64Encode(encodeURIComponent(JSON.stringify(app.$data))) + "</go-vue-data>"
renderer.renderToString(app, context, function (err, html) {
if (err) {
throw err
} else {
GoReturn(html);
}
})
}
eval(GoUseCallback)
var codes = GetGoVueJsCode(htmlparser2, GoHtmlSrc)
for(var i in codes){
eval("with(this){" + codes[i] + "}")
}
})()
})

211
govue2/govue.go

@ -0,0 +1,211 @@
package govue2
//go-bindata-assetfs --pkg=govue govue-runtime/...
import (
"fmt"
"git.ouxuan.net/3136352472/go-service-template/jsruntime"
"git.ouxuan.net/3136352472/go-service-template/pool"
"github.com/elazarl/go-bindata-assetfs"
"io/ioutil"
"log"
"net/http"
"os"
"path/filepath"
"time"
)
type GoVue struct {
StaticPath string
UseJsPath string
ErrorPage404 string
Resources *assetfs.AssetFS
IsDebugMode bool
jsRuntimePool *pool.JsRuntimePool
CacheSec int64
}
func NewGoVueDefaultConfig(debug bool) (gv *GoVue, err error) {
gv = &GoVue{
Resources: assetFS(),
IsDebugMode: debug,
}
err = gv.initRender(debug)
return
}
func NewGoVue(useJsPath string, staticPath string, debug bool) (gv *GoVue, err error) {
gv = &GoVue{
StaticPath: staticPath,
UseJsPath: useJsPath,
Resources: assetFS(),
IsDebugMode: debug,
}
err = gv.initRender(debug)
return
}
func (gv *GoVue) SetCacheSec(cacheSec int64) {
gv.CacheSec = cacheSec
}
func (gv *GoVue) SetErrorPage404(page string) {
gv.ErrorPage404 = page
}
func SetPoolConfig(config pool.Config) {
pool.DefaultConfig = config
}
func (gv *GoVue) initRender(debug bool) (err error) {
if gv.StaticPath == "" {
gv.StaticPath = filepath.Join(getSelfFilePath(), "static")
}
if gv.UseJsPath == "" {
gv.UseJsPath = filepath.Join(gv.StaticPath, "use.js")
}
headerScript, err := gv.Resources.Asset(filepath.Join("govue-runtime", "header.js"))
if err != nil {
return
}
polyfill, err := gv.Resources.Asset(filepath.Join("govue-runtime", "polyfill.js"))
if err != nil {
return
}
mainScript, err := gv.Resources.Asset(filepath.Join("govue-runtime", "runtime.js"))
if err != nil {
return
}
govueScriptFile := "govue.js"
govueScript, err := gv.Resources.Asset(filepath.Join("govue-runtime", govueScriptFile))
if err != nil {
return
}
gv.jsRuntimePool = pool.NewJsRuntimePool(string(mainScript), gv.UseJsPath, gv.StaticPath, jsruntime.Relys{
jsruntime.Rely{
Src: string(headerScript),
},
jsruntime.Rely{
Src: string(polyfill),
},
jsruntime.Rely{
Src: string(govueScript),
},
}, jsruntime.ModeSync, debug)
return
}
func (gv *GoVue) PoolLog() {
gv.jsRuntimePool.Log()
}
func (gv *GoVue) StartPoolLog() {
go func() {
defer func() {
recover()
log.Println("统计协程异常")
}()
lastidle := 0
lastactive := 0
for {
all, idle, active := gv.jsRuntimePool.NumInfo()
if idle != lastidle || active != lastactive {
fmt.Println("渲染协程数量变动变动:所有:", all, "空闲:", idle, "活动:", active)
}
lastidle = idle
lastactive = active
time.Sleep(time.Second)
}
}()
}
func (gv *GoVue) LoadStaticResources(request *http.Request, goExtDataS ...interface{}) (result []byte, err error) {
cacheKey := fmt.Sprintf("%s|%s", request.URL.Path, request.URL.RawQuery)
if gv.CacheSec > 0 {
html := GetCache(cacheKey)
if html != "" {
//log.Println("加载缓存")
return []byte(html), nil
}
}
//log.Println("非缓存", cacheKey)
var staticDir string
var filePath = request.URL.Path
if gv.StaticPath == "" {
staticDir = filepath.Join(getSelfFilePath(), "static")
} else {
staticDir = gv.StaticPath
}
filePath = filepath.Join(staticDir, filePath)
fi, err := os.Stat(filePath)
if err == nil {
if fi.IsDir() {
defaultPath := []string{"index.html"}
for e := range defaultPath {
path := filepath.Join(filePath, defaultPath[e])
_, err := os.Stat(path)
if err == nil {
filePath = path
break
}
}
}
}
result, err = ioutil.ReadFile(filePath)
if err != nil {
result, err = gv.renderErrPage(404, request, goExtDataS...)
if gv.CacheSec > 0 {
SetCache(cacheKey, string(result), gv.CacheSec)
}
return
}
if filepath.Ext(filePath) != ".html" {
return
}
err = gv.jsRuntimePool.JsRuntimeCall(func(jr *jsruntime.JsRuntime) {
err = jr.Render(filePath, fmt.Sprintf("http://%s%s", request.Host, request.RequestURI), string(result), nil, func(data string) {
result = []byte(data)
if gv.CacheSec > 0 {
SetCache(cacheKey, string(result), gv.CacheSec)
}
})
if err != nil {
result = []byte(err.Error())
}
})
return
}
func (gv *GoVue) renderErrPage(errCode int, request *http.Request, goExtDataS ...interface{}) (result []byte, err error) {
filePath := gv.ErrorPage404
if filePath == "" {
return []byte("页面不存在"), err
}
result, _ = ioutil.ReadFile(filePath)
var goExtData interface{}
if len(goExtDataS) > 0 {
goExtData = goExtDataS[0]
}
err = gv.jsRuntimePool.JsRuntimeCall(func(jr *jsruntime.JsRuntime) {
err = jr.Render(filePath, fmt.Sprintf("http://%s%s", request.Host, request.RequestURI), string(result), goExtData, func(data string) {
result = []byte(data)
})
})
return
}

58
govue2/utils.go

@ -0,0 +1,58 @@
package govue2
import (
"encoding/json"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"strings"
)
func pathExists(path string) bool {
_, err := os.Stat(path)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
return false
}
var selfFilePath string
func getSelfFilePath() string {
if selfFilePath == "" {
file, err := exec.LookPath(os.Args[0])
if err != nil {
return ""
}
path, err := filepath.Abs(file)
if err != nil {
return ""
}
i := strings.LastIndex(path, "/")
if i < 0 {
i = strings.LastIndex(path, "\\")
}
if i < 0 {
return ""
}
selfFilePath, _ = filepath.Abs(string(path[0 : i+1]))
}
return selfFilePath
}
func jsonToFile(file string, v interface{}) bool {
data, err := json.Marshal(v)
if err != nil {
return false
}
return ioutil.WriteFile(file, data, 0644) == nil
}
func jsonByFile(file string, v interface{}) {
data, _ := ioutil.ReadFile(file)
json.Unmarshal(data, v)
}

51
jsruntime/runtime.go

@ -2,6 +2,7 @@ package jsruntime
import ( import (
"crypto/md5" "crypto/md5"
"encoding/base64"
"fmt" "fmt"
"github.com/dop251/goja" "github.com/dop251/goja"
"html" "html"
@ -25,6 +26,7 @@ type JsRuntime struct {
mutex sync.Mutex mutex sync.Mutex
RenderCallBackFun func(string) RenderCallBackFun func(string)
IsDebugModel bool IsDebugModel bool
isRenderIng bool
} }
type Rely struct { type Rely struct {
@ -59,6 +61,15 @@ func NewJsRuntime(mainScript string, extFileDir string, rels Relys, mode RunMode
jr.EnableConsoleFun() jr.EnableConsoleFun()
jr.SetVariable("Base64Decode", func(text string) string {
code, _ := base64.StdEncoding.DecodeString(text)
return string(code)
})
jr.SetVariable("Base64Encode", func(text string) string {
code := base64.StdEncoding.EncodeToString([]byte(text))
return code
})
jr.SetVariable("GoReadFile", func(filePath string) string { jr.SetVariable("GoReadFile", func(filePath string) string {
code, err := ioutil.ReadFile(filepath.Join(jr.ExtFileDir, filePath)) code, err := ioutil.ReadFile(filepath.Join(jr.ExtFileDir, filePath))
if err != nil { if err != nil {
@ -93,8 +104,10 @@ func NewJsRuntime(mainScript string, extFileDir string, rels Relys, mode RunMode
} }
func (jr *JsRuntime) PrintError(msg string, code string) { func (jr *JsRuntime) PrintError(msg string, code string) {
log.Println(msg)
if !jr.IsDebugModel { if !jr.IsDebugModel {
log.Println(msg)
return
} }
var errLine string var errLine string
@ -127,16 +140,24 @@ func (jr *JsRuntime) PrintError(msg string, code string) {
if len(lines)-1 < linesEnd { if len(lines)-1 < linesEnd {
linesEnd = len(lines) linesEnd = len(lines)
} }
log.Println("error line linesEnd", linesEnd)
//linesEnd = linesStart + linesEnd
for e := range lines[linesStart:linesEnd] {
if e+linesStart+1 == line {
lines[linesStart:linesEnd][e] = fmt.Sprintf(`%2d: >>>>>> %s`, e+linesStart, lines[linesStart:linesEnd][e])
} else {
lines[linesStart:linesEnd][e] = fmt.Sprintf(`%2d: %s`, e+linesStart, lines[linesStart:linesEnd][e])
if linesStart > linesEnd {
errLine = "无法定位的报错位置"
linesStart = 0
} else {
//
//log.Println("error line linesStart", linesStart)
//log.Println("error line linesEnd", linesEnd)
//linesEnd = linesStart + linesEnd
for e := range lines[linesStart:linesEnd] {
if e+linesStart+1 == line {
lines[linesStart:linesEnd][e] = fmt.Sprintf(`%2d: >>>>>> %s`, e+linesStart, lines[linesStart:linesEnd][e])
} else {
lines[linesStart:linesEnd][e] = fmt.Sprintf(`%2d: %s`, e+linesStart, lines[linesStart:linesEnd][e])
}
} }
errLine = strings.Join(lines[linesStart:linesEnd], "\n")
} }
errLine = strings.Join(lines[linesStart:linesEnd], "\n")
} }
if jr.RenderCallBackFun != nil { if jr.RenderCallBackFun != nil {
@ -201,6 +222,7 @@ func (jr *JsRuntime) RunCode(code string) error {
} }
func (jr *JsRuntime) Render(filePath, href, tplSrc string, GoExtData interface{}, cb func(data string)) (err error) { func (jr *JsRuntime) Render(filePath, href, tplSrc string, GoExtData interface{}, cb func(data string)) (err error) {
jr.RenderCallBackFun = cb jr.RenderCallBackFun = cb
jr.mutex.Lock() jr.mutex.Lock()
defer jr.mutex.Unlock() defer jr.mutex.Unlock()
@ -208,9 +230,11 @@ func (jr *JsRuntime) Render(filePath, href, tplSrc string, GoExtData interface{}
runtime := jr.runtime runtime := jr.runtime
mainSrc := jr.MainSrc mainSrc := jr.MainSrc
isLock := true isLock := true
jr.isRenderIng = true
//timeoutSec := jr.TimeoutSec //timeoutSec := jr.TimeoutSec
defer func() { defer func() {
jr.isRenderIng = false
isLock = false isLock = false
jr.runtime.ClearInterrupt() jr.runtime.ClearInterrupt()
}() }()
@ -250,15 +274,18 @@ func (jr *JsRuntime) Render(filePath, href, tplSrc string, GoExtData interface{}
jr.RenderCallBackFun(data) jr.RenderCallBackFun(data)
}) })
t := time.AfterFunc(time.Duration(jr.TimeoutSec), func() {
jr.runtime.Interrupt("time out")
jr.runtime.ClearInterrupt()
t := time.AfterFunc(time.Duration(jr.TimeoutSec)*time.Second, func() {
if jr.isRenderIng {
jr.runtime.Interrupt("time out")
jr.runtime.ClearInterrupt()
}
}) })
defer t.Stop() defer t.Stop()
err = jr.RunCode(mainSrc) err = jr.RunCode(mainSrc)
if err != nil { if err != nil {
jr.PrintError(err.Error(), "")
return err return err
} }

2
jsruntime/timeout.go

@ -15,7 +15,7 @@ func (jr *JsRuntime) EnableTimeoutFunc() {
if len(call.Arguments) > 2 { if len(call.Arguments) > 2 {
args = call.Arguments[2:] args = call.Arguments[2:]
} }
//
//time.Sleep(time.Duration(delay) * time.Millisecond) //time.Sleep(time.Duration(delay) * time.Millisecond)
fn(nil, args...) fn(nil, args...)

7
pool/pool.go

@ -69,7 +69,7 @@ func NewJsRuntimePool(mainScript string, useFileName string, staticPath string,
}() }()
for { for {
jrp.jsRuntimePool.PreparePool(jrp.ctx) jrp.jsRuntimePool.PreparePool(jrp.ctx)
time.Sleep(time.Second / 5)
time.Sleep(time.Second)
} }
} }
go preparePoolTask() go preparePoolTask()
@ -84,7 +84,7 @@ func NewJsRuntimePool(mainScript string, useFileName string, staticPath string,
for { for {
raw, _ := ioutil.ReadFile(useFileName) raw, _ := ioutil.ReadFile(useFileName)
useSrc = string(raw) useSrc = string(raw)
time.Sleep(time.Second)
time.Sleep(time.Second * 3)
} }
} }
go useSrcTask() go useSrcTask()
@ -101,7 +101,8 @@ func (jrp *JsRuntimePool) JsRuntimeCall(call func(jr *jsruntime.JsRuntime)) (err
o := obj.(*jsruntime.JsRuntime) o := obj.(*jsruntime.JsRuntime)
call(o) call(o)
err = jrp.jsRuntimePool.ReturnObject(jrp.ctx, obj)
err = jrp.jsRuntimePool.InvalidateObject(jrp.ctx, obj)
//err = jrp.jsRuntimePool.ReturnObject(jrp.ctx, obj)
return return
} }

3
readme.md

@ -27,6 +27,7 @@
+ location[不完备的dom环境] + location[不完备的dom环境]
## 扩展方法 ## 扩展方法
+ Vue.UseRaw().component(..)[vue原始模板替换,不进行渲染]
+ GoUse(call function(ctx))[所有请求都经过该方法,优先于内联模式] + GoUse(call function(ctx))[所有请求都经过该方法,优先于内联模式]
+ GoUseRegistered(id string,call function(query))[注册id标签对应的方法,优先于内联模式] + GoUseRegistered(id string,call function(query))[注册id标签对应的方法,优先于内联模式]
+ GetGoVueId()[获取当前页面Id] + GetGoVueId()[获取当前页面Id]
@ -37,7 +38,7 @@
+ GoHtmlSrc[当前html原始代码,请不要使用] + GoHtmlSrc[当前html原始代码,请不要使用]
+ GoParam[请求参数,map形式] + GoParam[请求参数,map形式]
+ GoExtData[扩展数据,例如获取cookie,GoExtData['cookie'] ] + GoExtData[扩展数据,例如获取cookie,GoExtData['cookie'] ]
+ Vue.GV [用于判断是否处于服务端环境]
## 扩展标签 ## 扩展标签
+ gv-id 定义页面ID,只能在html上 + gv-id 定义页面ID,只能在html上

112
static/index.html

@ -1,36 +1,104 @@
<!doctype html>
<html lang="zh" gv-id="index">
<!DOCTYPE html>
<html lang="zh">
<head> <head>
<meta charset="utf-8">
<meta name="keywords" content="">
<link rel="stylesheet" href="css/main.css">
<title>{{ title }}</title>
<script src="js/vue.js"></script> <script src="js/vue.js"></script>
</head> </head>
<body> <body>
<div id="app">
<div class="content">
<my-title></my-title>
<a v-on:click="click" gv-ignore>{{desc}}</a>
<br>
<!--gv-start-->
<div>
<div>{{title1}}</div>
<div>{{title2}}</div>
<assssss>{{title2}}</assssss>
<div>{{title3}}</div>
<a href="#" @click="click">{{title3}}</a>
<div id="app-4">
<ol>
<li v-for="todo in todos">
<a href="#" @click="click(todo.text)"> {{ todo.text }}</a>
</li>
</ol>
</div>
<input v-model="message" placeholder="edit me">
<textarea v-model="message" placeholder="add multiple lines"></textarea>
<p>Original message: "{{ message }}"</p>
<p>Computed reversed message: "{{ reversedMessage }}"</p>
<input type="checkbox" id="jack" value="Jack" v-model="checkedNames">
<label for="jack">Jack</label>
<input type="checkbox" id="john" value="John" v-model="checkedNames">
<label for="john">John</label>
<input type="checkbox" id="mike" value="Mike" v-model="checkedNames">
<label for="mike">Mike</label>
<br>
<span>Checked names: {{ checkedNames }}</span>
<div id="example-4">
<input type="radio" id="one" value="One" v-model="picked">
<label for="one">One</label>
<br> <br>
<input type="radio" id="two" value="Two" v-model="picked">
<label for="two">Two</label>
<br> <br>
<a href="#" v-on:click="ssr" gv-ignore>{{a}}</a>
<span>Picked: {{ picked }}</span>
</div> </div>
<select v-model="selected">
<option v-for="option in options" v-bind:value="option.value">
{{ option.text }}
</option>
</select>
<span>Selected: {{ selected }}</span>
</div> </div>
<!--gv-end-->
</body> </body>
<script>
new Vue({
el: "#app",
<script src="js/govue.js"></script>
<script gv-src>
var app = new Vue({
data: {
message: 'Hello',
title1: "123",
title2: "456",
title3: "789",
todos: [
{text: '学习 JavaScript'},
{text: '学习 Vue'},
{text: '整个牛项目'},
{text: '{{a}}'}
],
checkedNames: [],
picked: '',
selected: 'A',
options: [
{text: 'One', value: 'A'},
{text: 'Two', value: 'B'},
{text: 'Three', value: 'C'}
]
},
computed: {
// 计算属性的 getter
reversedMessage: function () {
// `this` 指向 vm 实例
return this.message.split('').reverse().join('')
}
},
methods: { methods: {
click: function () {
alert("点击触发");
},
ssr: function () {
location.href = "ssr.html?test"
click: function (a) {
alert("点击触发:" + a);
}, },
}
},
}); });
GoVueMount(app, {
title: "123"
}, "body > div")
</script> </script>
</html>
</html>

41
static/index.html.bak

@ -0,0 +1,41 @@
<!doctype html>
<html lang="zh" gv-id="index">
<head>
<meta charset="utf-8">
<meta name="keywords" content="">
<link rel="stylesheet" href="css/main.css">
<script src="js/vue.js"></script>
</head>
<body>
<div id="app">
<div class="content">
<my-title></my-title>
<template v-for="desc in descs">
<li >
<a @click="click" gv-ignore="@click">{{desc}}</a>
</li>
</template>
<br>
<br>
<br>
<a href="#" v-on:click="ssr" gv-ignore>{{a}}</a>
</div>
</div>
</body>
<script>
new Vue({
el: "#app",
methods: {
click: function () {
alert("点击触发");
},
ssr: function () {
location.href = "ssr.html?test"
},
}
});
</script>
</html>

6
static/index.js

@ -1,6 +0,0 @@
new Vue({
el: "#pre",
data: {
pre: "扩展参数\nhtml上的gv属性,值为页面id\nserc上的gv属性,表示脚本需要服务端渲染"
}
});

21
static/js/govue.js

@ -0,0 +1,21 @@
window.isBrowser = true;
function GoVueMount(app, ctx, el) {
var sourceTemplate = document.getElementsByTagName("go-vue-template");
var GoVueHTML = "";
if (sourceTemplate.length > 0) {
GoVueHTML = decodeURIComponent(atob(sourceTemplate[0].innerHTML))
}
var sourceData = document.getElementsByTagName("go-vue-data");
var GoVueData = {};
if (sourceData.length > 0) {
GoVueData = JSON.parse(decodeURIComponent(atob(sourceData[0].innerHTML)))
}
app.$options.template = GoVueHTML;
app.$mount(el);
for (var i in GoVueData) {
app[i] = GoVueData[i];
}
}

38
static/router.html

@ -0,0 +1,38 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<title>{{ title }}</title>
<script src="js/vue.js"></script>
</head>
<body>
<!--gv-start-->
<div>
<h1>Hello App!</h1>
<p>
<router-link to="/foo">Go to Foo</router-link>
<router-link to="/bar">Go to Bar</router-link>
</p>
<router-view></router-view>
</div>
<!--gv-end-->
</body>
<script src="js/govue.js"></script>
<script gv-src>
var routes = [
{ path: '/router.html', component: {template: '123'}},
{path: '/bar.html', component: {template: '123'}}
]
var router = new VueRouter({
mode: 'history',
routes: routes
})
var app = new Vue({});
GoVueMount(app, {
title: "123"
})
</script>
</html>

12
static/template/ssr.html

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="zh">
<head>
<title>{{ title }}</title>
</head>
<body>
<!--vue-ssr-outlet-->
</body>
</html>

24
static/use.js

@ -2,28 +2,4 @@
GoUse(function () { GoUse(function () {
}); });
//分页面
GoUseRegistered("index", function (query) {
// 定义一个名为 button-counter 的新组件
document.title = "govue";
document
.getElementsByName("keywords")[0]
.setAttribute("content", "govue,服务端渲染,ssr");
Vue.component('my-title', {
template: '<h1 id="title">govue</h1>'
});
new Vue({
el: "#app",
data: {
"desc": "基础golang开发的一套vue服务端渲染方案",
"a": "官方ssr模式",
},
});
});
Loading…
Cancel
Save