diff --git a/src/components/code/index.js b/src/components/code/index.js new file mode 100644 index 0000000..6628dfe --- /dev/null +++ b/src/components/code/index.js @@ -0,0 +1,30 @@ +import Intact from 'intact'; +import template from './index.vdt'; +import hljs from 'highlight.js/lib/highlight'; +import stylus from 'highlight.js/lib/languages/stylus'; +import js from 'highlight.js/lib/languages/javascript'; +import html from 'highlight.js/lib/languages/xml'; +import 'highlight.js/styles/color-brewer.css'; + +hljs.registerLanguage('stylus', stylus); +hljs.registerLanguage('js', js); +hljs.registerLanguage('html', html); + +export default class Code extends Intact { + @Intact.template() + static template = template; + + defaults() { + return { + language: 'stylus', + }; + } + + _mount() { + this.on('$changed:code', () => { + hljs.highlightBlock(this.refs.code); + }); + hljs.highlightBlock(this.refs.code); + } +} + diff --git a/src/components/code/index.vdt b/src/components/code/index.vdt new file mode 100644 index 0000000..9295def --- /dev/null +++ b/src/components/code/index.vdt @@ -0,0 +1,5 @@ +
+    
+        {{ self.get('code') }}
+    
+
diff --git a/src/components/codePreview/index.js b/src/components/codePreview/index.js index e716c33..50d4022 100644 --- a/src/components/codePreview/index.js +++ b/src/components/codePreview/index.js @@ -1,29 +1,8 @@ import Intact from 'intact'; import template from './index.vdt'; import './index.styl'; -import hljs from 'highlight.js/lib/highlight'; -import stylus from 'highlight.js/lib/languages/stylus'; -import 'highlight.js/styles/color-brewer.css'; - -hljs.registerLanguage('stylus', stylus); - -class Code extends Intact { - @Intact.template() - static template = `
{self.get('code')}
`; - - _mount() { - this.on('$changed:code', () => { - hljs.highlightBlock(this.refs.code); - }); - hljs.highlightBlock(this.refs.code); - } -} export default class CodePreview extends Intact { @Intact.template() static template = template; - - _init() { - this.Code = Code; - } } diff --git a/src/components/codePreview/index.vdt b/src/components/codePreview/index.vdt index 14bddd7..c007205 100644 --- a/src/components/codePreview/index.vdt +++ b/src/components/codePreview/index.vdt @@ -1,6 +1,5 @@ -import {Split } from 'kpc'; - -const Code = self.Code; +import {Split} from 'kpc'; +import Code from '../code'; diff --git a/src/components/usage/index.js b/src/components/usage/index.js new file mode 100644 index 0000000..d46a1ca --- /dev/null +++ b/src/components/usage/index.js @@ -0,0 +1,16 @@ +import Dialog from 'kpc/components/dialog'; +import Intact from 'intact'; +import template from './index.vdt'; +import './index.styl'; + +export default class extends Dialog { + @Intact.template() + static template = template; + + defaults() { + return { + ...super.defaults(), + title: '使用说明', + }; + } +} diff --git a/src/components/usage/index.styl b/src/components/usage/index.styl new file mode 100644 index 0000000..a84521e --- /dev/null +++ b/src/components/usage/index.styl @@ -0,0 +1,8 @@ +.usage-dialog + .k-body + max-height 400px + overflow auto + .links + margin-left 16px + a + margin 0 8px diff --git a/src/components/usage/index.vdt b/src/components/usage/index.vdt new file mode 100644 index 0000000..b572c3a --- /dev/null +++ b/src/components/usage/index.vdt @@ -0,0 +1,37 @@ +import Code from '../code'; + +const link = ` + +` +const code = `const path = require('path'); + +... +{ + loader: 'stylus-loader', + options: { + 'include css': true, + 'resolve url': true, + 'import': path.resolve(__dirname, 'path/to/theme/index.styl') + } +} +`; + + + + 使用说明 + + 详情请参考kpc文档 + Intact / + Vue / + React + + + +

全量引入主题

+

如果你没有通过webpack编译打包,则可以全量引入主题样式,使用index.css替换掉kpc.css即可

+ +

通过webpack stylus-loader引入主题

+

如果你通过webpack编译打包,则可以配置stylus-loader来按需引入主题样式

+ +
+
diff --git a/src/pages/index/index.js b/src/pages/index/index.js index dfa9c15..84d4288 100644 --- a/src/pages/index/index.js +++ b/src/pages/index/index.js @@ -109,4 +109,10 @@ export default class Index extends Intact { _download() { window.open(`/api/download?id=${this.get('id')}`); } + + async _helper() { + const Dialog = await import('@/components/usage'); + const dialog = new Dialog.default(); + dialog.show(); + } } diff --git a/src/pages/index/index.vdt b/src/pages/index/index.vdt index 5fa524c..15cf010 100644 --- a/src/pages/index/index.vdt +++ b/src/pages/index/index.vdt @@ -21,6 +21,7 @@ import CodePreview from '@/components/codePreview'; KPC主题定制工具
+