mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-30 04:42:45 +08:00
检测是否已安装或需要更新
This commit is contained in:
parent
5f9af8987c
commit
8286b66c1e
@ -69,10 +69,21 @@
|
|||||||
:color="
|
:color="
|
||||||
!commands[count - 1]?.features.platform.includes(platform)
|
!commands[count - 1]?.features.platform.includes(platform)
|
||||||
? 'grey'
|
? 'grey'
|
||||||
|
: needUpdateCodes.includes(
|
||||||
|
commands[count - 1]?.features.code
|
||||||
|
)
|
||||||
|
? 'negative'
|
||||||
: 'primary'
|
: 'primary'
|
||||||
"
|
"
|
||||||
icon="download"
|
icon="download"
|
||||||
label="导入"
|
:label="
|
||||||
|
needUpdateCodes.includes(commands[count - 1]?.features.code)
|
||||||
|
? '更新'
|
||||||
|
: '导入'
|
||||||
|
"
|
||||||
|
v-show="
|
||||||
|
!installedCodes.includes(commands[count - 1]?.features.code)
|
||||||
|
"
|
||||||
><q-tooltip
|
><q-tooltip
|
||||||
v-if="
|
v-if="
|
||||||
!commands[count - 1]?.features.platform.includes(platform)
|
!commands[count - 1]?.features.platform.includes(platform)
|
||||||
@ -128,6 +139,8 @@ export default {
|
|||||||
initCommands: [],
|
initCommands: [],
|
||||||
matchedCommands: [],
|
matchedCommands: [],
|
||||||
commands: [],
|
commands: [],
|
||||||
|
installedCodes: [],
|
||||||
|
needUpdateCodes: [],
|
||||||
currentPage: 1,
|
currentPage: 1,
|
||||||
perPage: 8,
|
perPage: 8,
|
||||||
commandSearchKeyword: "",
|
commandSearchKeyword: "",
|
||||||
@ -150,13 +163,7 @@ export default {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
window.yuQueClient(`repos/${this.releaseRepo}/docs`).then((res) => {
|
this.fetchCommands();
|
||||||
this.initCommands = res.data.data.sort(
|
|
||||||
(x, y) => y.updated_at - x.updated_at
|
|
||||||
);
|
|
||||||
this.matchedCommands = _.cloneDeep(this.initCommands);
|
|
||||||
this.fetchCommandDetails(1);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
currentPage(val) {
|
currentPage(val) {
|
||||||
@ -182,9 +189,9 @@ export default {
|
|||||||
let code = command?.features?.code;
|
let code = command?.features?.code;
|
||||||
if (!code)
|
if (!code)
|
||||||
return quickcommand.showMessageBox("该命令格式有误!", "error");
|
return quickcommand.showMessageBox("该命令格式有误!", "error");
|
||||||
|
this.installedCodes.push(code);
|
||||||
let pushData = _.cloneDeep(command);
|
let pushData = _.cloneDeep(command);
|
||||||
pushData.fromShare = true;
|
pushData.fromShare = true;
|
||||||
if (!pushData?.tags.includes("来自分享")) pushData.tags.push("来自分享");
|
|
||||||
this.$root.utools.putDB(
|
this.$root.utools.putDB(
|
||||||
_.cloneDeep(pushData),
|
_.cloneDeep(pushData),
|
||||||
this.$root.utools.DBPRE.QC + code
|
this.$root.utools.DBPRE.QC + code
|
||||||
@ -216,11 +223,45 @@ export default {
|
|||||||
res.data?.data.body.match(/```json([\s\S]*)```/)?.[1]
|
res.data?.data.body.match(/```json([\s\S]*)```/)?.[1]
|
||||||
);
|
);
|
||||||
if (!command) return;
|
if (!command) return;
|
||||||
command.authorName = authorName;
|
Object.assign(command, { authorName, updateTime });
|
||||||
command.updateTime = updateTime;
|
command.updateTime = updateTime;
|
||||||
localStorage.setItem(id, JSON.stringify(command));
|
localStorage.setItem(id, JSON.stringify(command));
|
||||||
return command;
|
return command;
|
||||||
},
|
},
|
||||||
|
fetchCommands() {
|
||||||
|
window.yuQueClient(`repos/${this.releaseRepo}/docs`).then((res) => {
|
||||||
|
// 按更新日期排序
|
||||||
|
this.initCommands = res.data.data.sort((x, y) =>
|
||||||
|
this.compareTime(y.content_updated_at, x.content_updated_at)
|
||||||
|
);
|
||||||
|
this.checkCommands();
|
||||||
|
this.matchedCommands = _.cloneDeep(this.initCommands);
|
||||||
|
this.fetchCommandDetails(1);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
checkCommands() {
|
||||||
|
let installed = [];
|
||||||
|
let needUpdate = [];
|
||||||
|
this.$root.utools.getDocs(this.$root.utools.DBPRE.QC).forEach((item) => {
|
||||||
|
if (!item.data.fromShare) return;
|
||||||
|
let code = item._id.slice(3);
|
||||||
|
if(code.includes('pro')) console.log(code);
|
||||||
|
let remote = this.initCommands.filter((cmd) => cmd.slug === code)[0];
|
||||||
|
if (!remote) return;
|
||||||
|
let localUpdateTime =
|
||||||
|
item.data.updateTime || "2022-04-01T00:00:00.000Z";
|
||||||
|
if (this.compareTime(remote.content_updated_at, localUpdateTime) > 0) {
|
||||||
|
needUpdate.push(code);
|
||||||
|
_.pull(this.initCommands, remote);
|
||||||
|
this.initCommands.unshift(remote);
|
||||||
|
} else installed.push(code);
|
||||||
|
this.installedCodes = installed;
|
||||||
|
this.needUpdateCodes = needUpdate;
|
||||||
|
});
|
||||||
|
},
|
||||||
|
compareTime(x, y) {
|
||||||
|
return new Date(x).getTime() - new Date(y).getTime();
|
||||||
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user