Parcourir la source

feat: vscode plugin

王家程 il y a 3 ans
Parent
commit
62526aa1f2
7 fichiers modifiés avec 177 ajouts et 38 suppressions
  1. 20 0
      extension.js
  2. 0 0
      extensionUtils.js
  3. 5 5
      openHuiKaiFa.js
  4. 1 1
      package.json
  5. 0 0
      plugin/dbData/db.json
  6. 151 0
      plugin/index.html
  7. 0 32
      src/extension.js

+ 20 - 0
extension.js

@@ -0,0 +1,20 @@
+/*
+ * @Author: wjc
+ * @Date: 2021-12-13 11:29:50
+ * @LastEditors: wjc
+ * @LastEditTime: 2021-12-22 10:25:22
+ * @Description:
+ */
+
+const vscode = require('vscode')
+
+/**
+ * 插件被释放时触发
+ * @param {vscode.ExtensionContext} context
+ */
+exports.deactivate = function () { }
+
+exports.activate = function (context) {
+  // eslint-disable-next-line
+  require('./openHuiKaiFa')(context)
+}

+ 0 - 0
src/extensionUtils.js → extensionUtils.js


+ 5 - 5
openHuiKaiFa.js

@@ -2,7 +2,7 @@
  * @Author: wjc
  * @Date: 2021-12-14 15:05:05
  * @LastEditors: wjc
- * @LastEditTime: 2021-12-16 15:17:26
+ * @LastEditTime: 2021-12-22 10:03:46
  * @Description:
  */
 /* eslint-disable */
@@ -11,7 +11,7 @@ const fs = require('fs')
 const path = require('path')
 const open = require('open')
 
-const DB_PATH = path.join(__dirname, './dbData/db.json')
+const DB_PATH = path.join(__dirname, './plugin/dbData/db.json')
 
 function getExtensionFileAbsolutePath(context, relativePath) {
   return path.join(context.extensionPath, relativePath)
@@ -22,7 +22,7 @@ function getExtensionFileAbsolutePath(context, relativePath) {
  * @param {*} context 上下文
  * @param {*} templatePath 相对于插件根目录的html文件相对路径
  */
-function getWebViewContent(context, templatePath) {
+ function getWebViewContent(context, templatePath) {
   const resourcePath = getExtensionFileAbsolutePath(context, templatePath)
   const dirPath = path.dirname(resourcePath)
   let html = fs.readFileSync(resourcePath, 'utf-8')
@@ -83,8 +83,8 @@ module.exports = function (context) {
           pclintBar.hide()
         }
       })
-      panel.webview.html = getWebViewContent(context, 'dist/index.html')
-      panel.webview.html = '<html><body>你好,我是Webview</body></html>'
+      panel.webview.html = getWebViewContent(context, 'plugin/index.html')
+      // panel.webview.html = '<html><body>你好,我是Webview</body></html>'
       panel.webview.postMessage({
         cmd: 'setSrc',
         data: {

+ 1 - 1
package.json

@@ -14,7 +14,7 @@
   "activationEvents": [
 		"*"
 	],
-  "main": "./out/extension.js",
+  "main": "./extension.js",
   "contributes": {
 		"commands": [
 			{

+ 0 - 0
src/dbData/db.json → plugin/dbData/db.json


+ 151 - 0
plugin/index.html

@@ -0,0 +1,151 @@
+<!--
+ * @Author: wjc
+ * @Date: 2021-12-22 10:03:00
+ * @LastEditors: wjc
+ * @LastEditTime: 2021-12-22 10:03:00
+ * @Description: 
+-->
+<!DOCTYPE html>
+<html lang="zh">
+
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width,initial-scale=0,maximum-scale=0,user-scalable=yes,shrink-to-fit=no">
+  <title>form generator</title>
+  <style>
+    html,
+    body {
+      height: 100%;
+      overflow: hidden;
+      padding: 0;
+      margin: 0;
+    }
+
+    #frame {
+      display: none;
+    }
+  </style>
+  <style>
+    .pre-loader {
+      position: absolute;
+      top: calc(50% - 32px);
+      left: calc(50% - 32px);
+      width: 64px;
+      height: 64px;
+      border-radius: 50%;
+      perspective: 800px;
+    }
+
+    .pre-loader .inner {
+      position: absolute;
+      box-sizing: border-box;
+      width: 100%;
+      height: 100%;
+      border-radius: 50%;
+    }
+
+    .pre-loader .inner.one {
+      left: 0%;
+      top: 0%;
+      -webkit-animation: rotate-one 1s linear infinite;
+      animation: rotate-one 1s linear infinite;
+      border-bottom: 3px solid #bc9048;
+    }
+
+    .pre-loader .inner.two {
+      right: 0%;
+      top: 0%;
+      -webkit-animation: rotate-two 1s linear infinite;
+      animation: rotate-two 1s linear infinite;
+      border-right: 3px solid #74aeff;
+    }
+
+    .pre-loader .inner.three {
+      right: 0%;
+      bottom: 0%;
+      -webkit-animation: rotate-three 1s linear infinite;
+      animation: rotate-three 1s linear infinite;
+      border-top: 3px solid #caef74;
+    }
+
+    @keyframes rotate-one {
+      0% {
+        -webkit-transform: rotateX(35deg) rotateY(-45deg) rotateZ(0deg);
+        transform: rotateX(35deg) rotateY(-45deg) rotateZ(0deg);
+      }
+
+      100% {
+        -webkit-transform: rotateX(35deg) rotateY(-45deg) rotateZ(360deg);
+        transform: rotateX(35deg) rotateY(-45deg) rotateZ(360deg);
+      }
+    }
+
+    @keyframes rotate-two {
+      0% {
+        -webkit-transform: rotateX(50deg) rotateY(10deg) rotateZ(0deg);
+        transform: rotateX(50deg) rotateY(10deg) rotateZ(0deg);
+      }
+
+      100% {
+        -webkit-transform: rotateX(50deg) rotateY(10deg) rotateZ(360deg);
+        transform: rotateX(50deg) rotateY(10deg) rotateZ(360deg);
+      }
+    }
+
+    @keyframes rotate-three {
+      0% {
+        -webkit-transform: rotateX(35deg) rotateY(55deg) rotateZ(0deg);
+        transform: rotateX(35deg) rotateY(55deg) rotateZ(0deg);
+      }
+
+      100% {
+        -webkit-transform: rotateX(35deg) rotateY(55deg) rotateZ(360deg);
+        transform: rotateX(35deg) rotateY(55deg) rotateZ(360deg);
+      }
+    }
+  </style>
+</head>
+
+<body>
+  <div class="pre-loader" id="pre-loader">
+    123
+    <div class="inner one"></div>
+    <div class="inner two"></div>
+    <div class="inner three"></div>
+  </div>
+  <iframe id="frame" width="100%" height="100%" frameborder="0"></iframe>
+  <script>
+    window.onload = function () {
+      const vscode = acquireVsCodeApi()
+      const cmds = {
+        setSrc: function (message) {
+          var frame = document.getElementById('frame')
+          frame.src = message.data.src
+          frame.onload = function () {
+            document.getElementById('pre-loader').style.display = "none"
+            frame.style.display = "block"
+            frame.contentWindow.postMessage({
+              cmd: 'mountApp',
+              data: message.data.db // 发送db.json中的内容
+            }, '*')
+          }
+        },
+        writeFile: function (message) {
+          vscode.postMessage(message)
+        },
+        openUrl: function (message) {
+          vscode.postMessage(message)
+        },
+        setStorageItem: function (message) {
+          vscode.postMessage(message)
+        }
+      }
+
+      window.addEventListener('message', event => {
+        const message = event.data
+        if (message && message.cmd) cmds[message.cmd](message)
+      })
+    }
+  </script>
+</body>
+</html>

+ 0 - 32
src/extension.js

@@ -1,32 +0,0 @@
-/*
- * @Author: wjc
- * @Date: 2021-12-13 11:29:50
- * @LastEditors: wjc
- * @LastEditTime: 2021-12-16 11:59:31
- * @Description:
- */
-import { getWebViewContent, resolveHandle } from './extensionUtils'
-
-const vscode = require('vscode')
-
-/**
- * 插件被释放时触发
- */
-export function deactivate() { }
-
-export function activate(context) {
-  context.subscriptions.push(vscode.commands.registerCommand('extension.openHuiKaiFa', () => {
-    // 创建webview
-    const panel = vscode.window.createWebviewPanel(
-      'huikaifa',
-      '绘开发',
-      vscode.ViewColumn.One,
-      {
-        enableScripts: true, // 启用js
-        retainContextWhenHidden: true // webview被隐藏时,保持状态
-      }
-    )
-    panel.webview.html = getWebViewContent(context, 'dist/index.html')
-    panel.webview.onDidReceiveMessage(msg => resolveHandle(msg, panel), undefined, context.subscriptions)
-  }))
-}