diff --git a/src/assets/options.js b/src/assets/options.js index a352383..6e3f25d 100644 --- a/src/assets/options.js +++ b/src/assets/options.js @@ -32,7 +32,6 @@ } catch (error) { return false } - console.log(qc); if (isJsonQc(qc)) return { single: true, qc: qc } else if (!Object.values(qc).filter(q => !isJsonQc(q)).length) return { single: false, qc: qc } else return false @@ -77,21 +76,15 @@ } let clearAll = () => { - Swal.fire({ - text: '将会清空所有命令,请确认!', - icon: 'warning', - showCancelButton: true, - confirmButtonColor: '#3085d6', - cancelButtonColor: '#d33', - confirmButtonText: '确定!', - cancelButtonText: '手抖...', - }).then((result) => { - if (result.value) { - utools.db.remove('customFts'); - clearAllFeatures(); - showOptions(); - } - }) + quickcommand.showConfirmBox('将会清空所有命令,请确认!').then(() => { + utools.db.remove('customFts'); + clearAllFeatures(); + showOptions(); + }) + } + + let overwriteConfirm = () => { + } programs = { @@ -273,7 +266,7 @@
@@ -659,11 +652,11 @@
let extraInfo = {
authorName: data.authorName,
authorId: data.authorId,
- docId: data.docId
+ fromShare: data.fromShare
}
- $('#options').data('extraInfo', extraInfo)
if (data.tags && data.tags.includes("默认")) readonly = true
showCustomize(readonly);
+ $('#customize').data('extraInfo', extraInfo)
data.tags && $('#tags').val(data.tags).trigger('change')
platform && ["win32", "darwin", "linux"].map(x => (!platform.includes(x) && $(`#${x}`).addClass('disabled')))
$('#type').val(cmds.type).trigger("change")
@@ -787,10 +780,11 @@
let extraInfo = getDB('extraInfo')
if (jsonQc.authorId) {
if (jsonQc.authorId == extraInfo.authorId) menu[2] = '更新分享'
+ else if (jsonQc.fromShare) menu[2] = '评论'
else menu[2] = '分享自:' + jsonQc.authorName
} else {
if (extraInfo.yuQueToken) menu[2] = '分享命令'
- else menu[2] = '☛ 分享命令'
+ else menu[2] = '我要分享'
}
return menu
}
@@ -813,16 +807,16 @@
}, stringifyQc)
break;
case '分享命令':
- var result = await shareQCToYuQue(jsonQc)
- result && quickcommand.showMessageBox('分享成功')
- break;
case '更新分享':
- var result = await shareQCToYuQue(jsonQc, true)
- result && quickcommand.showMessageBox('分享成功')
+ var result = await shareQCToYuQue(jsonQc)
+ result && quickcommand.showMessageBox('分享成功,等待发布后即可在分享中心直接下载')
break;
- case '☛ 分享命令':
+ case '我要分享':
utools.createBrowserWindow('./helps/HELP.html?#分享命令', {width: 1280, height: 920})
break;
+ case '评论':
+ utools.shellOpenExternal(`https://www.yuque.com/fofolee/qcreleases/${code}`)
+ break;
case '设置 Token':
await setYuQueToken()
break;
@@ -830,7 +824,7 @@
})
// 一键分享到语雀
- let shareQCToYuQue = async (jsonQc, update = false) => {
+ let shareQCToYuQue = async jsonQc => {
let extraInfo = getDB('extraInfo')
if (!extraInfo.yuQueToken) return quickcommand.showMessageBox("请先设置 Token,点击底部「查看帮助」可查看 Token 设置方法", "error")
jsonQc.authorId = extraInfo.authorId
@@ -850,42 +844,42 @@
custom_description: `作者:${jsonQc.authorName} | 环境:${jsonQc.program} | 匹配:${type} | 平台:${platform} | 标签:${tags}`
}
yuQueClient.defaults.headers['X-Auth-Token'] = extraInfo.yuQueToken
- let res
+ let res, repo = extraInfo.authorId == 1496740 ? 'qcreleases' : 'qcshares'
+ console.log(repo);
try {
- if (update) res = await yuQueClient.put('repos/fofolee/em2rng/docs/' + jsonQc.docId, parameters)
- else res = await yuQueClient.post('repos/fofolee/em2rng/docs', parameters)
- if (res.data.data) {
- jsonQc.docId = res.data.data.id
- putDB(jsonQc.features.code, jsonQc, 'customFts');
- return jsonQc
- } else {
- return quickcommand.showMessageBox("分享失败,不知道为啥", "error")
- }
+ res = await yuQueClient.post(`repos/fofolee/${repo}/docs`, parameters)
+ if (!res.data.data) return quickcommand.showMessageBox("分享失败,不知道为啥", "error")
+ let docId = res.data.data.id
+ res = await yuQueClient.put(`repos/fofolee/${repo}/docs/${docId}`, parameters)
+ if (!res.data.data) return quickcommand.showMessageBox("分享失败,不知道为啥", "error")
+ putDB(jsonQc.features.code, jsonQc, 'customFts');
+ return jsonQc
} catch (error) {
return quickcommand.showMessageBox(error, "error")
}
}
- getSharedQCFromYuQue = async () => {
+ let getSharedQCFromYuQue = async () => {
$('#options').hide()
let extraInfo = getDB('extraInfo')
if (extraInfo.yuQueToken) yuQueClient.defaults.headers['X-Auth-Token'] = extraInfo.yuQueToken
- let res = await yuQueClient('repos/fofolee/em2rng/docs')
- let docs = res.data.data.map(d => {
+ let res = await yuQueClient('repos/fofolee/qcreleases/docs')
+ let program, docs = res.data.data.map(d => {
+ program = d.custom_description.match(/环境:(.*?) /)
return {
title: d.title,
description: d.custom_description,
slug: d.slug,
- icon: d.last_editor.avatar_url
+ icon: `logo/${program[1]}.png`
}
})
let choise = await quickcommand.showSelectList(docs, { optionType: 'json' })
- let doc = await yuQueClient(`repos/fofolee/em2rng/docs/${choise.slug}?raw=1`)
+ let doc = await yuQueClient(`repos/fofolee/qcreleases/docs/${choise.slug}?raw=1`)
let body = doc.data.data.body
let stringifyQc = body.match(/```json([\s\S]*)```/)[1]
let qc = JSON.parse(stringifyQc)
$('#options').show()
- qc.docId = doc.data.data.id
+ qc.fromShare = true
editCurrentCommand(qc)
utools.setExpendHeight(600)
}
@@ -899,27 +893,17 @@
// 删除
$("#options").on('click', '.delBtn', function () {
- Swal.fire({
- text: '删除这个快捷命令',
- icon: 'warning',
- showCancelButton: true,
- confirmButtonColor: '#3085d6',
- cancelButtonColor: '#d33',
- confirmButtonText: '确定!',
- cancelButtonText: '手抖...',
- }).then((result) => {
- if (result.value) {
- var code = $(this).parents('tr').attr('id'),
- db = utools.db.get("customFts"),
- data = db.data;
- delete data[code];
- utools.removeFeature(code);
- utools.db.put({ _id: "customFts", data: data, _rev: db._rev });
- var currentTag = $('.currentTag').text()
- if ($('#featureList tr').length == 2) currentTag = "默认"
- showOptions(currentTag);
- }
- })
+ quickcommand.showConfirmBox('删除这个快捷命令').then(() => {
+ var code = $(this).parents('tr').attr('id'),
+ db = utools.db.get("customFts"),
+ data = db.data;
+ delete data[code];
+ utools.removeFeature(code);
+ utools.db.put({ _id: "customFts", data: data, _rev: db._rev });
+ var currentTag = $('.currentTag').text()
+ if ($('#featureList tr').length == 2) currentTag = "默认"
+ showOptions(currentTag);
+ })
})
// 选择图标
@@ -967,7 +951,7 @@
if (iconame) {
base64ico = window.getBase64Ico(iconpath);
icon = "data:image/png;base64," + base64ico;
- // 未自定义使用默认
+ // 未自定义使用默认
} else {
icon = iconpath;
}
@@ -1017,9 +1001,9 @@
}
// platform
var platform = []
- $('.platform').not('.disabled').each(function() { platform.push($(this).attr('id')) })
+ $('.platform').not('.disabled').each(function () { platform.push($(this).attr('id')) })
// 添加特性
- var extraInfo = $('#options').data('extraInfo')
+ var extraInfo = $('#customize').data('extraInfo')
var pushData = {
features: {
"code": code,
@@ -1032,11 +1016,9 @@
cmd: cmd,
output: output,
hasSubInput: hasSubInput,
- scptarg: scptarg,
- authorId: extraInfo.authorId,
- authorName: extraInfo.authorName,
- docId: extraInfo.docId
+ scptarg: scptarg
}
+ if (extraInfo) Object.assign(pushData, extraInfo)
if (tags) pushData.tags = tags
if (program == 'custom') {
pushData.customOptions = {