Skip to content
This repository was archived by the owner on May 12, 2021. It is now read-only.

Commit 01bce26

Browse files
committed
init
0 parents  commit 01bce26

17 files changed

+12743
-0
lines changed

.browserslistrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> 1%
2+
last 2 versions

.editorconfig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[*.{js,jsx,ts,tsx,vue}]
2+
indent_style = space
3+
indent_size = 2
4+
trim_trailing_whitespace = true
5+
insert_final_newline = true

.eslintrc.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module.exports = {
2+
root: true,
3+
env: {
4+
node: true
5+
},
6+
'extends': [
7+
'plugin:vue/essential',
8+
'@vue/standard'
9+
],
10+
rules: {
11+
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
12+
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
13+
},
14+
parserOptions: {
15+
parser: 'babel-eslint'
16+
}
17+
}

.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.DS_Store
2+
node_modules
3+
/dist
4+
5+
# local env files
6+
.env.local
7+
.env.*.local
8+
9+
# Log files
10+
npm-debug.log*
11+
yarn-debug.log*
12+
yarn-error.log*
13+
14+
# Editor directories and files
15+
.idea
16+
.vscode
17+
*.suo
18+
*.ntvs*
19+
*.njsproj
20+
*.sln
21+
*.sw?

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2019 二当家的
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.m

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# vue-ele-form-codemirror | vue-ele-form 的代码编辑器
2+
3+
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.svg)](https://opensource.org/licenses/mit-license.php)
4+
[![npm](https://img.shields.io/npm/v/vue-ele-form-codemirror.svg)](https://www.npmjs.com/package/vue-ele-form-codemirror)
5+
[![download](https://img.shields.io/npm/dw/vue-ele-form-codemirror.svg)](https://npmcharts.com/compare/vue-ele-form-codemirror?minimal=true)
6+
7+
## 介绍
8+
9+
vue-ele-form-codemirror 做为 [vue-ele-form](https://github.com/dream2023/vue-ele-form) 的第三方扩展, 通过对 [vue-codemirror](https://github.com/surmon-china/vue-codemirror) 的二次封装, 实现代码编辑器的扩展
10+
11+
![image](https://raw.githubusercontent.com/dream2023/images/master/vue-ele-codemirror.ep8rp5ce6q8.png)
12+
13+
## 安装
14+
15+
```bash
16+
npm install vue-ele-form-codemirror --save
17+
```
18+
19+
## 使用
20+
21+
```js
22+
import EleForm from 'vue-ele-form'
23+
import EleFormCodemirror from 'vue-ele-form-codemirror'
24+
// 以下仅为示例, 具体根据需要, 在局部或者全局引入相应的资源
25+
// 属性和引用资源参考: https://github.com/surmon-china/vue-codemirror
26+
// language js
27+
import 'codemirror/mode/javascript/javascript.js'
28+
// theme css
29+
import 'codemirror/theme/base16-dark.css'
30+
31+
// 注册 codemirror 组件
32+
Vue.component('codemirror', EleFormCodemirror)
33+
34+
// 注册 vue-ele-form
35+
Vue.use(EleForm, {
36+
// 可以为编辑器配置全局属性, 每个实例都共享这个属性
37+
codemirror: {
38+
options: {
39+
theme: 'base16-dark',
40+
tabSize: 4,
41+
mode: 'text/javascript',
42+
lineNumbers: true,
43+
line: true
44+
}
45+
// events: ['scroll', ...]
46+
}
47+
})
48+
```
49+
50+
```js
51+
formDesc: {
52+
xxx: {
53+
label: 'xxx',
54+
type: 'codemirror', // 只需要在这里指定为 codemirror 即可
55+
attrs: {
56+
// 属性配置(会覆盖全局配置)
57+
options: {
58+
tabSize: 4,
59+
mode: 'text/javascript',
60+
theme: 'base16-dark',
61+
lineNumbers: true,
62+
line: true,
63+
}
64+
}
65+
}
66+
}
67+
```
68+
69+
## 相关链接
70+
71+
- [vue-codemirror](https://github.com/surmon-china/vue-codemirror)
72+
- [vue-ele-form](https://github.com/dream2023/vue-ele-form)
73+
- [element-ui](http://element-cn.eleme.io)

babel.config.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
presets: [
3+
'@vue/app'
4+
]
5+
}

example/App.vue

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<template>
2+
<el-card
3+
header="ele-form-codemirror 演示"
4+
shadow="never"
5+
style="max-width: 1250px;margin: 20px auto;"
6+
>
7+
<ele-form
8+
:form-data="formData"
9+
:form-desc="formDesc"
10+
:request-fn="handleRequest"
11+
:span="22"
12+
@request-success="handleSuccess"
13+
/>
14+
</el-card>
15+
</template>
16+
17+
<script>
18+
export default {
19+
name: 'App',
20+
data () {
21+
return {
22+
formData: {
23+
content: ''
24+
},
25+
formDesc: {
26+
content: {
27+
label: '代码',
28+
type: 'codemirror'
29+
}
30+
}
31+
}
32+
},
33+
methods: {
34+
handleRequest (data) {
35+
console.log(data)
36+
return Promise.resolve()
37+
},
38+
handleSuccess () {
39+
this.$message.success('提交成功')
40+
}
41+
},
42+
mounted () {}
43+
}
44+
</script>
45+
46+
<style>
47+
body {
48+
background-color: #f0f2f5;
49+
}
50+
</style>

example/main.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Vue from 'vue'
2+
import App from './App.vue'
3+
import ElementUI from 'element-ui'
4+
import EleForm from 'vue-ele-form'
5+
import EleFormCodemirror from '../lib/index'
6+
import 'element-ui/lib/theme-chalk/index.css'
7+
import 'codemirror/mode/javascript/javascript.js'
8+
import 'codemirror/theme/base16-dark.css'
9+
10+
Vue.config.productionTip = false
11+
12+
Vue.use(ElementUI)
13+
Vue.component('codemirror', EleFormCodemirror)
14+
Vue.use(EleForm, {
15+
codemirror: {
16+
options: {
17+
theme: 'base16-dark',
18+
tabSize: 4,
19+
mode: 'text/javascript',
20+
lineNumbers: true,
21+
line: true
22+
}
23+
// events: ['scroll', ...]
24+
}
25+
})
26+
27+
new Vue({
28+
render: h => h(App)
29+
}).$mount('#app')

lib/EleFormCodemirror.vue

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<template>
2+
<div class="ele-form-codemirror">
3+
<vue-codemirror
4+
:class="desc.class"
5+
:style="desc.style"
6+
v-bind="attrs"
7+
v-model="newValue"
8+
v-on="onEvents"
9+
/>
10+
</div>
11+
</template>
12+
13+
<script>
14+
import { codemirror } from 'vue-codemirror'
15+
import 'codemirror/lib/codemirror.css'
16+
import formMixin from 'vue-ele-form/lib/mixins/formMixin'
17+
18+
export default {
19+
name: 'codemirror',
20+
mixins: [formMixin],
21+
components: {
22+
'vue-codemirror': codemirror
23+
},
24+
data () {
25+
return {
26+
defaultAttrs: {
27+
options: {
28+
tabSize: 4,
29+
lineNumbers: true,
30+
line: true
31+
}
32+
}
33+
}
34+
}
35+
}
36+
</script>
37+
38+
<style>
39+
.ele-form-codemirror {
40+
line-height: 1.3;
41+
}
42+
</style>

lib/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import EleFormCodemirror from './EleFormCodemirror'
2+
3+
export default EleFormCodemirror

0 commit comments

Comments
 (0)