Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

03. 自定义WebView欢迎页面-例子 #3

Open
PDKSophia opened this issue Feb 4, 2021 · 0 comments
Open

03. 自定义WebView欢迎页面-例子 #3

PDKSophia opened this issue Feb 4, 2021 · 0 comments
Labels
documentation Improvements or additions to documentation vscode

Comments

@PDKSophia
Copy link
Owner

PDKSophia commented Feb 4, 2021

场景

该插件场景适合做一些简单页面展示、欢迎页面等

代码展示

// demo3 自定义显示页
// 具体看 package.json 中的 configuration 和 commands
import * as vscode from 'vscode'
import * as fs from 'fs'
import * as path from 'path'

module.exports = function (context: vscode.ExtensionContext) {
  let disposable = vscode.commands.registerCommand(
    'beehive.customWelcome',
    () => {
      const panel = vscode.window.createWebviewPanel(
        'welcome',
        '自定义欢迎页',
        vscode.ViewColumn.One,
        {
          enableScripts: true,
        }
      )

      const htmlPath = path.join(
        context.extensionPath,
        'src/customWelcome.html'
      )
      let html = fs.readFileSync(htmlPath, 'utf-8')
      panel.webview.html = html
    }
  )

  context.subscriptions.push(disposable)
}
// extension.ts
import * as vscode from 'vscode'

export function activate(context: vscode.ExtensionContext) {
  console.log('your extension "sugar-demo-vscode" is now active!')
  require('./beehive-customWelcome')(context) // demo3 加载自定义WebView欢迎页
}

export function deactivate() {}
// package.json
"commands": [
    {
       "command": "beehive.customWelcome",
       "title": "demo4: beehive.customWelcome !"
    }
],
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>demo3 自定义欢迎页面</title>
        <style>
            .app {
                margin: 12px 0;
                font-size: 24px;
            }
            .title {
                font-size: 18px;
                margin-top: 24px;
            }
        </style>
    </head>
    <body>
        <div class="app">
            Welcome BeeHiver ~
            <div class="title">后人哀之而不鉴之 亦使后人而复哀后人也 !</div>
        </div>
        <img src="https://media.giphy.com/media/JIX9t2j0ZTN9S/giphy.gif" width="300" />
    </body>
</html>

效果展示

源码展示

@PDKSophia PDKSophia added documentation Improvements or additions to documentation vscode labels Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation vscode
Projects
None yet
Development

No branches or pull requests

1 participant