Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
夜猫逐梦
1024程序员开源挑战赛
提交
dfd4f646
1
1024程序员开源挑战赛
项目概览
夜猫逐梦
/
1024程序员开源挑战赛
与 Fork 源项目一致
Fork自
GitCode / 1024程序员开源挑战赛(10.23-11.14)
通知
3
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
1
1024程序员开源挑战赛
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
dfd4f646
编写于
10月 26, 2021
作者:
B
baiy
提交者:
ninecents
10月 23, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update codeEditor
上级
624ba488
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
73 addition
and
53 deletion
+73
-53
src/tool.js
src/tool.js
+0
-2
src/views/tool/code.vue
src/views/tool/code.vue
+22
-13
src/views/tool/components/codeEditor.vue
src/views/tool/components/codeEditor.vue
+30
-32
src/views/tool/ip.vue
src/views/tool/ip.vue
+6
-1
src/views/tool/json.vue
src/views/tool/json.vue
+4
-0
src/views/tool/jsonToObject.vue
src/views/tool/jsonToObject.vue
+6
-2
src/views/tool/library/formatter.js
src/views/tool/library/formatter.js
+5
-3
未找到文件。
src/tool.js
浏览文件 @
dfd4f646
...
...
@@ -4,7 +4,6 @@ import './statics/theme.less'
import
router
from
'
./tool.router
'
import
optionBlock
from
'
./components/optionBlock
'
import
{
plugin
as
modelPlugin
}
from
'
./tool/model
'
import
codeEditor
from
"
./views/tool/components/codeEditor
"
;
import
cache
from
'
./tool/cache
'
import
setting
from
'
./tool/setting
'
import
App
from
'
./tool.vue
'
...
...
@@ -19,7 +18,6 @@ const run = () => {
Vue
.
use
(
ViewUI
)
Vue
.
use
(
modelPlugin
)
Vue
.
component
(
'
option-block
'
,
optionBlock
);
Vue
.
component
(
'
code-editor
'
,
codeEditor
);
new
Vue
({
router
,
...
...
src/views/tool/code.vue
浏览文件 @
dfd4f646
<
template
>
<div>
<div
style=
"border: 1px solid #dcdee2; border-radius: 4px"
>
<code-editor
ref=
"editor"
v-model=
"current.content"
auto-height=
"220"
:language=
"this.current.lang"
></code-editor>
<code-editor
ref=
"editor"
v-model=
"current.content"
:
auto-height=
"220"
:language=
"this.current.lang"
></code-editor>
</div>
<option-block>
<FormItem>
...
...
@@ -25,7 +25,11 @@
</
template
>
<
script
>
import
_
from
"
lodash
"
;
import
codeEditor
from
"
./components/codeEditor
"
;
export
default
{
components
:
{
codeEditor
,
},
computed
:{
buttonLang
(){
let
data
=
_
.
slice
(
this
.
lang
,
0
,
8
)
...
...
@@ -35,21 +39,25 @@ export default {
return
data
}
},
created
()
{
this
.
current
=
Object
.
assign
(
this
.
current
,
this
.
$getToolData
(
"
content
"
))
},
methods
:
{
handle
(
language
)
{
this
.
current
.
lang
=
language
;
setTimeout
(()
=>
{
if
(
this
.
current
.
content
)
{
let
oldContent
=
this
.
current
.
content
;
this
.
$refs
.
editor
.
getEditor
().
getAction
(
'
editor.action.formatDocument
'
).
run
();
setTimeout
(()
=>
{
if
(
oldContent
!==
this
.
current
.
content
){
this
.
$saveToolData
(
this
.
current
);
return
this
.
$Message
.
success
(
'
格式化完成
'
);
}
},
300
)
if
(
this
.
current
.
content
)
{
try
{
this
.
current
.
lang
=
language
;
this
.
$refs
.
editor
.
format
(
language
);
this
.
$saveToolData
(
this
.
current
);
return
this
.
$Message
.
success
(
'
格式化完成
'
);
}
},
200
)
catch
(
e
)
{
return
this
.
$Modal
.
error
({
title
:
"
格式化错误
"
,
content
:
`
${
e
.
message
}
`
});
}
}
},
},
data
()
{
...
...
@@ -73,6 +81,7 @@ export default {
"
less
"
,
"
graphql
"
,
"
markdown
"
,
"
vue
"
,
],
};
},
...
...
src/views/tool/components/codeEditor.vue
浏览文件 @
dfd4f646
<
template
>
<div
ref=
"container"
class=
"monaco-editor"
:style=
"`height:$
{containerHeight};width:${width}`">
</div>
<div
ref=
"container"
class=
"code-editor"
:style=
"`height:$
{containerHeight};width:${width}`">
</div>
</
template
>
<
script
>
import
formatter
from
"
../library/formatter
"
;
import
*
as
monaco
from
'
monaco-editor/esm/vs/editor/editor.api
'
;
// 注册文本格式化服务
// html/typescript/javascript/json 使用内置服务
const
allowFormatterLanguage
=
[
{
id
:
"
css
"
,
format
:
"
css
"
},
{
id
:
"
graphql
"
,
format
:
"
graphql
"
},
{
id
:
"
java
"
,
format
:
"
java
"
},
{
id
:
"
markdown
"
,
format
:
"
markdown
"
},
{
id
:
"
php
"
,
format
:
"
php
"
},
{
id
:
"
scss
"
,
format
:
"
scss
"
},
{
id
:
"
sql
"
,
format
:
"
sql
"
},
{
id
:
"
xml
"
,
format
:
"
xml
"
},
{
id
:
"
yaml
"
,
format
:
"
yaml
"
},
]
for
(
let
lang
of
allowFormatterLanguage
)
{
monaco
.
languages
.
registerDocumentFormattingEditProvider
(
lang
.
id
,
{
provideDocumentFormattingEdits
(
model
)
{
return
[
{
range
:
model
.
getFullModelRange
(),
text
:
formatter
(
model
.
getValue
(),
lang
.
format
),
},
];
}
});
const
allowFormatterLanguage
=
{
html
:
"
html
"
,
typescript
:
"
ts
"
,
javascript
:
"
js
"
,
json
:
"
json
"
,
graphql
:
"
graphql
"
,
java
:
"
java
"
,
markdown
:
"
markdown
"
,
php
:
"
php
"
,
css
:
"
css
"
,
scss
:
"
scss
"
,
less
:
"
less
"
,
sql
:
"
sql
"
,
xml
:
"
xml
"
,
yaml
:
"
yaml
"
,
vue
:
"
vue
"
,
}
export
default
{
...
...
@@ -43,6 +33,10 @@ export default {
type
:
String
,
default
:
""
},
autoHeight
:
{
type
:
Number
,
default
:
0
},
theme
:
{
type
:
String
,
default
:
'
vs
'
...
...
@@ -51,10 +45,6 @@ export default {
type
:
Boolean
,
default
:
true
},
autoHeight
:
{
type
:
Number
,
default
:
0
},
height
:
{
type
:
String
,
default
:
"
350px
"
...
...
@@ -108,12 +98,20 @@ export default {
automaticLayout
:
true
})
this
.
editor
.
onDidChangeModelContent
(()
=>
{
this
.
$emit
(
'
input
'
,
this
.
editor
.
getValue
())
if
(
this
.
value
!==
this
.
editor
.
getValue
()){
this
.
$emit
(
'
input
'
,
this
.
editor
.
getValue
())
}
})
},
/** @return monaco.editor.IStandaloneCodeEditor*/
getEditor
()
{
return
this
.
editor
},
format
(
lang
,
option
=
{})
{
if
(
!
(
lang
in
allowFormatterLanguage
)){
throw
new
Error
(
"
当前代码无法格式化
"
);
}
this
.
$emit
(
'
input
'
,
formatter
(
this
.
editor
.
getValue
(),
allowFormatterLanguage
[
lang
],
option
))
}
}
};
...
...
src/views/tool/ip.vue
浏览文件 @
dfd4f646
...
...
@@ -15,15 +15,19 @@
</FormItem>
</option-block>
<div
style=
"border: 1px solid #dcdee2;border-radius: 4px;"
>
<code-editor
v-model=
"current.output"
language=
"json"
></code-editor>
<code-editor
v-model=
"current.output"
language=
"json"
></code-editor>
</div>
</div>
</
template
>
<
script
>
import
axios
from
"
axios
"
import
_
from
"
lodash
"
import
codeEditor
from
"
./components/codeEditor
"
;
export
default
{
components
:
{
codeEditor
,
},
created
()
{
this
.
current
=
Object
.
assign
(
this
.
current
,
this
.
$getToolData
(
"
input
"
))
},
...
...
@@ -36,6 +40,7 @@ export default {
}).
then
(({
data
})
=>
{
this
.
current
.
output
=
JSON
.
stringify
(
_
.
isArray
(
data
)
&&
data
.
length
<
2
?
data
[
0
]
:
data
,
null
,
4
);
this
.
$saveToolData
(
this
.
current
);
this
.
$Message
.
success
(
"
查询成功
"
)
}).
catch
((
error
)
=>
{
return
this
.
$Message
.
error
(
"
ip地址信息查询错误:
"
+
error
);
});
...
...
src/views/tool/json.vue
浏览文件 @
dfd4f646
...
...
@@ -14,8 +14,12 @@
</
template
>
<
script
>
import
Unicode
from
"
./library/unicode
"
import
codeEditor
from
"
./components/codeEditor
"
;
export
default
{
components
:
{
codeEditor
,
},
created
()
{
this
.
current
=
Object
.
assign
(
this
.
current
,
this
.
$getToolData
(
'
content
'
))
},
...
...
src/views/tool/jsonToObject.vue
浏览文件 @
dfd4f646
...
...
@@ -3,7 +3,7 @@
<Col
span=
"10"
>
<Card
:padding=
"0"
>
<p
slot=
"title"
>
JSON内容
</p>
<code-editor
v-model=
"current.json"
auto-height=
"330"
language=
"json"
></code-editor>
<code-editor
v-model=
"current.json"
:
auto-height=
"330"
language=
"json"
></code-editor>
</Card>
<option-block>
<FormItem>
...
...
@@ -28,18 +28,22 @@
@
click=
"handle(item)"
>
{{
item
}}
</Button>
</
template
>
<code-editor
v-model=
"current.output"
auto-height=
"220"
:language=
"languages[current.type]"
></code-editor>
<code-editor
v-model=
"current.output"
:
auto-height=
"220"
:language=
"languages[current.type]"
></code-editor>
</Card>
</Col>
</Row>
</template>
<
script
>
import
codeEditor
from
"
./components/codeEditor
"
;
import
json2Go
from
'
./library/json2Go
'
import
json2CSharp
from
'
./library/json2CSharp
'
import
json2Java
from
'
./library/json2Java
'
import
json2Dart
from
'
./library/json2Dart
'
export
default
{
components
:
{
codeEditor
,
},
created
()
{
this
.
current
=
Object
.
assign
(
this
.
current
,
this
.
$getToolData
())
},
...
...
src/views/tool/library/formatter.js
浏览文件 @
dfd4f646
...
...
@@ -25,15 +25,17 @@ const options = {
yaml
:
{
parser
:
"
yaml
"
,
plugins
:
[
parserYaml
]},
html
:
{
parser
:
"
html
"
,
plugins
:
[
parserHtml
]},
angular
:
{
parser
:
"
angular
"
,
plugins
:
[
parserHtml
]},
json
:
{
parser
:
"
json5
"
,
plugins
:
[
parserJson5
]},
json
:
{
parser
:
"
json5
"
,
plugins
:
[
parserJson5
]
,
quoteProps
:
"
preserve
"
,
trailingComma
:
"
none
"
},
xml
:
{
parser
:
"
xml
"
,
plugins
:
[
parserXml
]},
sql
:
{
parser
:
"
sql
"
,
plugins
:
[
parserSql
]},
php
:
{
parser
:
"
php
"
,
plugins
:
[
parserPhp
]},
java
:
{
parser
:
"
java
"
,
plugins
:
[
parserJava
]},
};
export
default
(
code
,
lang
)
=>
{
export
default
(
code
,
lang
,
{
tab
=
4
}
)
=>
{
if
(
!
(
lang
in
options
))
{
throw
new
Error
(
`
${
lang
}
can't format`
);
}
return
prettier
.
format
(
code
,
options
[
lang
]);
let
langOption
=
options
[
lang
];
langOption
.
tabWidth
=
tab
return
prettier
.
format
(
code
,
langOption
);
};
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录