mirror of
https://gitee.com/spark-store-project/spark-store
synced 2026-04-26 01:10:16 +08:00
feat(app): add download count display
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
</div>
|
||||
<p class="text-sm text-slate-500 dark:text-slate-400">
|
||||
{{ app?.pkgname || "" }} · {{ app?.version || "" }}
|
||||
<span v-if="downloadCount"> · 下载量:{{ downloadCount }}</span>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -199,7 +200,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, useAttrs } from "vue";
|
||||
import { computed, useAttrs, ref, watch } from "vue";
|
||||
import axios from "axios";
|
||||
import {
|
||||
useDownloadItemStatus,
|
||||
useInstallFeedback,
|
||||
@@ -255,6 +257,31 @@ const iconPath = computed(() => {
|
||||
return `${APM_STORE_BASE_URL}/${window.apm_store.arch}/${props.app.category}/${props.app.pkgname}/icon.png`;
|
||||
});
|
||||
|
||||
const downloadCount = ref<string>("");
|
||||
|
||||
// 监听 app 变化,获取新app的下载量
|
||||
watch(
|
||||
() => props.app,
|
||||
async (newApp) => {
|
||||
if (newApp) {
|
||||
downloadCount.value = "";
|
||||
try {
|
||||
const url = `${APM_STORE_BASE_URL}/${window.apm_store.arch}/${newApp.category}/${newApp.pkgname}/download-times.txt`;
|
||||
const resp = await axios.get(url, { responseType: "text" });
|
||||
if (resp.status === 200) {
|
||||
downloadCount.value = String(resp.data).trim();
|
||||
} else {
|
||||
downloadCount.value = "N/A";
|
||||
throw new Error(`Unexpected response status: ${resp.status}`);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error("Failed to fetch download count", e);
|
||||
}
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const closeModal = () => {
|
||||
emit("close");
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { App } from "./typedefinition";
|
||||
export const APM_STORE_BASE_URL: string =
|
||||
import.meta.env.VITE_APM_STORE_BASE_URL || "";
|
||||
|
||||
export const APM_STORE_STATS_BASE_URL: string =
|
||||
export const APM_STORE_STATS_BASE_URL: string =
|
||||
import.meta.env.VITE_APM_STORE_STATS_BASE_URL || "";
|
||||
|
||||
// 下面的变量用于存储当前应用的信息,其实用在多个组件中
|
||||
|
||||
@@ -74,7 +74,7 @@ export const handleInstall = () => {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
},
|
||||
)
|
||||
.then((response) => {
|
||||
logger.info("下载次数统计已发送,状态:", response.data);
|
||||
@@ -146,7 +146,7 @@ window.ipcRenderer.on(
|
||||
if (downloadObj) {
|
||||
downloadObj.progress = payload.progress;
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
window.ipcRenderer.on("install-log", (_event, log: InstallLog) => {
|
||||
|
||||
Reference in New Issue
Block a user