From 063aa8a12b13976b36f9f3df3edc75673572fb59 Mon Sep 17 00:00:00 2001 From: xu_yanfeng Date: Thu, 13 Feb 2025 10:56:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96popup=E7=9A=84=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scripts/inject-view/loader.ts | 29 ++++++++++++++----- src/views/popup/index.vue | 38 ++++-------------------- src/views/popup/tool-item.vue | 45 +++++++++++++++++++++++++++++ src/views/popup/tool.vue | 48 +++++++++++++++++++++++++++++++ src/views/popup/type.ts | 14 +++++++++ 5 files changed, 134 insertions(+), 40 deletions(-) create mode 100644 src/views/popup/tool-item.vue create mode 100644 src/views/popup/tool.vue create mode 100644 src/views/popup/type.ts diff --git a/src/scripts/inject-view/loader.ts b/src/scripts/inject-view/loader.ts index 3adbb86..c6e7c89 100644 --- a/src/scripts/inject-view/loader.ts +++ b/src/scripts/inject-view/loader.ts @@ -1,5 +1,6 @@ import CCPlugin from "../../../cc-plugin.config"; import { githubMirrorMgr } from "./github"; + export class AdItem { /** * 广告的名字 @@ -9,6 +10,10 @@ export class AdItem { * 鼠标悬浮提示 */ tip: string = ""; + /** + * 分类,目前支持2类:ai绘图、我的插件 + */ + type: string = ""; /** * 插件的试用地址 */ @@ -29,11 +34,13 @@ export class AdItem { * 背景图 */ img: string = ""; - getTryInfos(): Array<{ name: string; url: string }> { + getTryInfos(): Array<{ name: string; url: string; type: string }> { if (typeof this.try === "string" && this.try) { - return [{ name: this.name, url: this.try }]; + return [{ name: this.name, url: this.try, type: this.type }]; } else if (Array.isArray(this.try)) { - return this.try; + return this.try.map((el) => { + return { name: el.name, url: el.url, type: this.type }; + }); } return []; } @@ -44,6 +51,7 @@ export class AdItem { this.try = data.try || ""; this.tip = data.tip || ""; + this.type = data.type || ""; this.duration = data.duration || 0; this.valid = !!data.valid; const img = data.img || ""; @@ -80,7 +88,10 @@ export class AdData { * 展示的广告数量,-1为所有 */ showCount: number = -1; - + /** + * 类型对应文本 + */ + keys: Record = {}; data: Array = []; parse(data: AdData) { this.desc = data.desc; @@ -89,7 +100,7 @@ export class AdData { this.scrollDuration = data.scrollDuration || 3; this.randomIndex = !!data.randomIndex; this.showCount = data.showCount || -1; - + this.keys = data.keys || {}; if (data.data) { if (this.randomIndex) { data.data.sort(() => Math.random() - 0.5); @@ -100,13 +111,17 @@ export class AdData { } const item = new AdItem().parse(el); if (!item.duration) { - console.warn(`add failed, ad.duration is ${item.duration}, ${JSON.stringify(item)}`); - return; + // console.warn(`add failed, ad.duration is ${item.duration}, ${JSON.stringify(item)}`); } this.data.push(item); }); } } + sortByName() { + this.data.sort((a, b) => { + return a.name.localeCompare(b.name); + }); + } } export async function getAdData(): Promise { diff --git a/src/views/popup/index.vue b/src/views/popup/index.vue index fba828e..0abc9f3 100644 --- a/src/views/popup/index.vue +++ b/src/views/popup/index.vue @@ -24,15 +24,7 @@
-
个人开发的web在线游戏工具,无须安装,欢迎自荐,收录更多游戏开发工具。
-
-
    -
  1. - - {{ item.name }} -
  2. -
-
+
@@ -55,7 +47,7 @@ import { Page } from "../../core/types"; import { ga } from "../../ga"; import { GA_EventName } from "../../ga/type"; import Ad from "../../scripts/inject-view/ad.vue"; -import { getAdData } from "../../scripts/inject-view/loader"; +import Tools from "./tool.vue"; const { CCInput, CCButton, CCButtonGroup, CCInputNumber, CCSelect, CCCheckBox, CCColor } = ccui.components; enum ViewType { Support = "support", @@ -63,14 +55,10 @@ enum ViewType { Recommend = "recommend", OnlineTools = "onlineTools", } -interface Tools { - name: string; - url: string; - store: string; -} + export default defineComponent({ name: "popup", - components: { CCInput, CCButton, CCInputNumber, Ad, CCSelect, CCCheckBox, CCColor, CCButtonGroup }, + components: { CCInput, Tools, CCButton, CCInputNumber, Ad, CCSelect, CCCheckBox, CCColor, CCButtonGroup }, setup(props, ctx) { ga.openView(Page.Popup); const title = ref(CCP.manifest.name); @@ -92,18 +80,6 @@ export default defineComponent({ } onMounted(async () => { _initLongConn(); - const data = await getAdData(); - if (data) { - data.data.forEach((item) => { - item.getTryInfos().forEach((info) => { - onlineTools.value.push({ - name: info.name, - url: info.url, - store: item.store, - }); - }); - }); - } }); const items = ref([ { @@ -140,7 +116,6 @@ export default defineComponent({ }, ]); const viewType = ref(ViewType.Friends); - const onlineTools = ref([]); const chooseItem = ref(items.value[0]); const cocosStore = ref(PKG.manifest.store); const myPlugins = ref("https://store.cocos.com/app/search?name=xu_yanfeng"); @@ -154,10 +129,7 @@ export default defineComponent({ onClickBuyPlugins() { ga.fireEventWithParam(GA_EventName.Popup, myPlugins.value); }, - onClickTry(event: MouseEvent, url: string) { - ga.fireEventWithParam(GA_EventName.Popup, url); - }, - onlineTools, + isViewSupport() { return viewType.value === ViewType.Support; }, diff --git a/src/views/popup/tool-item.vue b/src/views/popup/tool-item.vue new file mode 100644 index 0000000..ff5f168 --- /dev/null +++ b/src/views/popup/tool-item.vue @@ -0,0 +1,45 @@ + + + diff --git a/src/views/popup/tool.vue b/src/views/popup/tool.vue new file mode 100644 index 0000000..ab7f0d5 --- /dev/null +++ b/src/views/popup/tool.vue @@ -0,0 +1,48 @@ + + + diff --git a/src/views/popup/type.ts b/src/views/popup/type.ts new file mode 100644 index 0000000..e21aa6c --- /dev/null +++ b/src/views/popup/type.ts @@ -0,0 +1,14 @@ +export interface Tools { + name: string; + url: string; + store: string; +} + +export class ToolItem { + constructor(type: string) { + this.type = type; + } + title: string = ""; + type: string = ""; + items: Tools[] = []; +}