feat: 支持自定义功能按钮

This commit is contained in:
ZiuChen 2022-09-18 16:04:31 +08:00
parent b071a9eb58
commit 1d3c6c7fe8
3 changed files with 16 additions and 9 deletions

View File

@ -5,28 +5,24 @@
"operation.shown": ["copy", "view", "collect", "remove"], "operation.shown": ["copy", "view", "collect", "remove"],
"operation.custom": [ "operation.custom": [
{ {
"id": "custom.1663468392",
"title": "讯飞OCR识别", "title": "讯飞OCR识别",
"icon": "⚡", "icon": "⚡",
"match": ["image"], "match": ["image", { "type": "file", "regex": ".(?:jpg|jpeg|png)$" }],
"command": "redirect:讯飞ocr" "command": "redirect:讯飞ocr"
}, },
{ {
"id": "custom.1663468466",
"title": "百度搜索", "title": "百度搜索",
"icon": "🔍", "icon": "🔍",
"match": ["text"], "match": ["text"],
"command": "redirect:百度一下" "command": "redirect:百度一下"
}, },
{ {
"id": "custom.1663468466",
"title": "上传到图床", "title": "上传到图床",
"icon": "🚀", "icon": "🚀",
"match": ["image", { "type": "file", "regex": ".(?:jpg|jpeg|png)$" }], "match": ["image", { "type": "file", "regex": ".(?:jpg|jpeg|png)$" }],
"command": "redirect:上传到图床" "command": "redirect:上传到图床"
}, },
{ {
"id": "custom.1663476961",
"title": "翻译", "title": "翻译",
"icon": "🌎", "icon": "🌎",
"match": ["text"], "match": ["text"],

View File

@ -15,6 +15,9 @@
width: 400px; width: 400px;
} }
} }
.el-textarea {
width: 70%;
}
.path { .path {
width: 65%; width: 65%;
} }

View File

@ -46,6 +46,10 @@
/> />
</el-select> </el-select>
</div> </div>
<div class="setting-card-content-item">
<span>自定义功能</span>
<el-input v-model="stringCustom" :rows="5" type="textarea" placeholder="Please input" />
</div>
</div> </div>
<div class="setting-card-footer"> <div class="setting-card-footer">
<el-button @click="handleRestoreBtnClick">重置</el-button> <el-button @click="handleRestoreBtnClick">重置</el-button>
@ -72,6 +76,7 @@ const maxage = ref(database.maxage)
const shown = ref(operation.shown) const shown = ref(operation.shown)
const custom = ref(operation.custom) const custom = ref(operation.custom)
const stringCustom = ref(JSON.stringify(operation.custom))
const handleLinkClick = (index) => { const handleLinkClick = (index) => {
const links = [ const links = [
@ -106,6 +111,12 @@ const handleSaveBtnClick = () => {
ElMessage.error('数据库路径不正确') ElMessage.error('数据库路径不正确')
return return
} }
try {
custom.value = JSON.parse(stringCustom.value)
} catch (error) {
custom.value = operation.custom
ElMessage.error('格式错误')
}
utools.dbStorage.setItem( utools.dbStorage.setItem(
'setting', 'setting',
JSON.parse( JSON.parse(
@ -122,10 +133,7 @@ const handleSaveBtnClick = () => {
}) })
) )
) )
ElMessage({ ElMessage.success('保存成功 重启插件生效')
message: '保存成功 重启插件生效',
type: 'success'
})
} }
const handleRestoreBtnClick = () => { const handleRestoreBtnClick = () => {