分享中心 40%

This commit is contained in:
fofolee 2022-04-15 12:44:21 +08:00
parent 0f6c2c371a
commit ce88da243b
4 changed files with 244 additions and 55 deletions

110
plugin/package-lock.json generated
View File

@ -6,6 +6,7 @@
"": {
"dependencies": {
"axios": "^0.24.0",
"axios-delay": "^1.0.0-rc6",
"iconv-lite": "^0.6.3",
"lodash": "^4.17.21"
}
@ -18,6 +19,43 @@
"follow-redirects": "^1.14.4"
}
},
"node_modules/axios-delay": {
"version": "1.0.0-rc6",
"resolved": "https://registry.npmjs.org/axios-delay/-/axios-delay-1.0.0-rc6.tgz",
"integrity": "sha512-l52QkvPb3/T1b5NqyjhXt3LU5lkYOSn0AFb9tXI8qApBv9kGvLQj0PG69s7T9aVtJDMsKakekIMNhJMyXzTJZg==",
"dependencies": {
"axios": "^0.18.0"
}
},
"node_modules/axios-delay/node_modules/axios": {
"version": "0.18.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz",
"integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==",
"deprecated": "Critical security vulnerability fixed in v0.21.1. For more information, see https://github.com/axios/axios/pull/3410",
"dependencies": {
"follow-redirects": "1.5.10",
"is-buffer": "^2.0.2"
}
},
"node_modules/axios-delay/node_modules/follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"dependencies": {
"debug": "=3.1.0"
},
"engines": {
"node": ">=4.0"
}
},
"node_modules/debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"dependencies": {
"ms": "2.0.0"
}
},
"node_modules/follow-redirects": {
"version": "1.14.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz",
@ -48,11 +86,38 @@
"node": ">=0.10.0"
}
},
"node_modules/is-buffer": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz",
"integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"engines": {
"node": ">=4"
}
},
"node_modules/lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"node_modules/ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
@ -68,6 +133,41 @@
"follow-redirects": "^1.14.4"
}
},
"axios-delay": {
"version": "1.0.0-rc6",
"resolved": "https://registry.npmjs.org/axios-delay/-/axios-delay-1.0.0-rc6.tgz",
"integrity": "sha512-l52QkvPb3/T1b5NqyjhXt3LU5lkYOSn0AFb9tXI8qApBv9kGvLQj0PG69s7T9aVtJDMsKakekIMNhJMyXzTJZg==",
"requires": {
"axios": "^0.18.0"
},
"dependencies": {
"axios": {
"version": "0.18.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.18.1.tgz",
"integrity": "sha512-0BfJq4NSfQXd+SkFdrvFbG7addhYSBA2mQwISr46pD6E5iqkWg02RAs8vyTT/j0RTnoYmeXauBuSv1qKwR179g==",
"requires": {
"follow-redirects": "1.5.10",
"is-buffer": "^2.0.2"
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
}
}
}
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
}
},
"follow-redirects": {
"version": "1.14.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz",
@ -81,11 +181,21 @@
"safer-buffer": ">= 2.1.2 < 3.0.0"
}
},
"is-buffer": {
"version": "2.0.5",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.5.tgz",
"integrity": "sha512-i2R6zNFDwgEHJyQUtJEk0XFi1i0dPFn/oqjK3/vPCcDeJvW5NQ83V8QbicfF1SupOaB0h8ntgBC2YiE7dfyctQ=="
},
"lodash": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz",
"integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",

View File

@ -1,6 +1,7 @@
{
"dependencies": {
"axios": "^0.24.0",
"axios-delay": "^1.0.0-rc6",
"iconv-lite": "^0.6.3",
"lodash": "^4.17.21"
}

View File

@ -12,10 +12,14 @@ const axios = require('axios');
const pictureCompress = require("./lib/picture-compressor")
window._ = require("lodash")
window.fetchGitee = async path => {
let res = await axios('https://gitee.com/api/v5/repos/fofolee/qcshares' + path)
return res.data
}
window.yuQueClient = axios.create({
baseURL: 'https://www.yuque.com/api/v2/',
headers: {
'Content-Type': 'application/json',
// 只读权限
'X-Auth-Token': 'WNrd0Z4kfCZLFrGLVAaas93DZ7sbG6PirKq7VxBL'
}
});
// axios.defaults.adapter = require('axios/lib/adapters/http')
@ -216,22 +220,22 @@ if (process.platform !== 'linux') quickcommand.runInTerminal = function(cmdline,
}
let getCommandToLaunchTerminal = (cmdline, dir) => {
let cd = ''
if (utools.isWindows()) {
let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/')
// 直接 existsSync wt.exe 无效
if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) {
cmdline = cmdline.replace(/"/g, `\\"`)
if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"`
command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`
} else {
cmdline = cmdline.replace(/"/g, `^"`)
if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&`
command = `${cd} start "" cmd /k "${cmdline}"`
}
} else {
let cd = ''
if (utools.isWindows()) {
let appPath = path.join(utools.getPath('home'), '/AppData/Local/Microsoft/WindowsApps/')
// 直接 existsSync wt.exe 无效
if (fs.existsSync(appPath) && fs.readdirSync(appPath).includes('wt.exe')) {
cmdline = cmdline.replace(/"/g, `\\"`)
if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&`
if (dir) cd = `-d "${dir.replace(/\\/g, '/')}"`
command = `${appPath}wt.exe ${cd} cmd /k "${cmdline}"`
} else {
cmdline = cmdline.replace(/"/g, `^"`)
if (dir) cd = `cd /d "${dir.replace(/\\/g, '/')}" &&`
command = `${cd} start "" cmd /k "${cmdline}"`
}
} else {
cmdline = cmdline.replace(/"/g, `\\"`)
if (dir) cd = `cd ${dir.replace(/ /g, `\\\\ `)} &&`
if (fs.existsSync('/Applications/iTerm.app')) {
command = `osascript -e 'tell application "iTerm"
create window with default profile

View File

@ -1,13 +1,22 @@
<template>
<div>
<div class="flex">
<div class="flex absolute-top" style="bottom: 60px; overflow-y: auto">
<div
style="width: 50%"
class="q-pa-sm"
v-for="count in perPage"
:key="count"
class="q-pa-sm wrapper"
v-for="command in commands.slice(
(currentPage - 1) * perPage,
currentPage * perPage
)"
:key="command"
>
<q-card class="my-card">
<q-card
class="my-card"
:style="{
padding: '8px',
background: $q.dark.isActive ? '#ffffff08' : '#00000008',
}"
>
<q-item v-if="loading">
<q-item-section avatar>
<q-skeleton square width="48px" height="48px" animation="fade" />
@ -21,26 +30,50 @@
<q-item v-else>
<q-item-section avatar>
<q-avatar square size="48px">
<q-img :src="commands[count - 1]?.features?.icon" />
<q-img :src="command?.avatar" />
</q-avatar>
</q-item-section>
<q-item-section>
<q-item-label class="text-h5">{{
commands[count - 1]?.features?.explain
}}</q-item-label>
<q-item-label caption>{{
commands[count - 1]?.program
}}</q-item-label>
<q-item-label caption>{{
commands[count - 1]?.features?.cmds[0]?.type || "key"
<q-item-label class="text-h6" lines="1">{{
command?.title
}}</q-item-label>
<q-item-label caption
><q-icon name="account_circle"></q-icon>{{ command?.user }}
<q-icon name="watch_later"></q-icon
>{{ command?.updateTime }}</q-item-label
>
<q-item-label caption
><q-icon name="fiber_manual_record"></q-icon
>{{ command?.program }}</q-item-label
>
<q-item-label caption>
<span
v-for="tag in [command?.type, ...command?.tags]"
:key="tag"
class="tag"
>
{{ tag }}
</span>
</q-item-label>
</q-item-section>
<q-btn flat>导入</q-btn>
<q-item-label side>
<q-btn
@click="importCommand(command.slug)"
flat
dense
color="primary"
icon="download"
label="导入"
></q-btn>
</q-item-label>
</q-item>
</q-card>
</div>
</div>
<div class="q-pa-sm flex flex-center">
<div
class="absolute flex flex-center"
:style="{ left: 0, right: 0, bottom: '10px' }"
>
<q-pagination v-model="currentPage" :max="maxPages" input />
</div>
</div>
@ -51,40 +84,81 @@ export default {
data() {
return {
currentPage: 1,
commandTree: [],
commands: [],
perPage: 12,
perPage: 8,
loading: true,
releaseRepo: "fofolee/qcreleases",
shareRepo: "fofolee/qcshares",
};
},
computed: {
maxPages() {
return this.commandTree.length || 1;
},
},
watch: {
currentPage(val) {
this.updateCommands(val);
return Math.ceil(this.commands.length / this.perPage) || 1;
},
},
mounted() {
window.fetchGitee("/contents/commands").then((res) => {
this.commandTree = res;
this.updateCommands(1);
this.loading = true;
window.yuQueClient(`repos/${this.releaseRepo}/docs`).then((res) => {
console.log(res.data);
this.commands = res.data.data
.map((item) => {
let info = JSON.parse(item.custom_description);
return {
title: item.title,
user: item.last_editor.name,
updateTime: item.content_updated_at.slice(0, 10),
avatar: item.last_editor.avatar_url,
tags: info.tags.split(" ").filter((x) => x), // tag
program: info.program,
platform: info.platform,
type: info.type,
slug: item.slug,
};
})
.filter((item) => item.platform.includes(window.processPlatform));
this.loading = false;
});
},
methods: {
updateCommands(page) {
this.loading = true;
this.commands = [];
this.commandTree
.slice((page - 1) * this.perPage, page * this.perPage)
.forEach(async (x) => {
let res = await window.fetchGitee(`/contents/commands/${x.name}`);
let command = JSON.parse(window.base64Decode(res.content));
this.commands.push(command);
importCommand(slug) {
window
.yuQueClient(`repos/${this.releaseRepo}/docs/${slug}?raw=1`)
.then((res) => {
let command = JSON.parse(
res.data?.data.body.match(/```json([\s\S]*)```/)?.[1]
);
if (!command)
return quickcommand.showMessageBox("导入出错!", "error");
command.tags.push("新添加");
let code = command?.features?.code;
if (!code)
return quickcommand.showMessageBox("该命令格式有误!", "error");
this.$utools.putDB(command, this.$utools.DBPRE.QC + code);
quickcommand.showMessageBox("导入成功!可到「来自分享」标签查看");
});
},
},
};
</script>
<style scoped>
.q-card {
user-select: none;
}
.tag {
background: var(--q-primary);
border-radius: 2px;
padding: 2px;
margin-right: 2px;
color: white;
}
.wrapper {
transition: 0.5s;
}
.wrapper:hover {
transition: 0.5s;
transform: translateY(-1px);
filter: drop-shadow(1px 1px 5px #0000008e);
}
</style>