Commit 7da45aa7 authored by KesaubeEire's avatar KesaubeEire

feat: 访问 info.json 01.

parent 68d12b2a
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
import { _env } from './stores'; import { _env } from './stores';
// ----------------------------- // -----------------------------
// 各种请求封装头 // 各种请求封装头 & 请求函数
/**请求封装头 -> 获取所有资料*/ /**请求封装头 -> 获取所有资料*/
const getContentsRequest = { const getContentsRequest = {
...@@ -34,13 +34,7 @@ ...@@ -34,13 +34,7 @@
}; };
}; };
// ----------------------------- /**创建请求 fetch 函数
// 变量 & 函数工具
/**渲染数据列表*/
let List = [];
/**创建 fetch 函数
* @param {object} param0 参数对象 * @param {object} param0 参数对象
* @param {function} callback 回调函数 * @param {function} callback 回调函数
*/ */
...@@ -63,11 +57,16 @@ ...@@ -63,11 +57,16 @@
.catch(error => { .catch(error => {
// 处理错误 // 处理错误
console.error('网络请求错误:', error); console.error('网络请求错误:', error);
我处理一下就行;
toast.push('网络请求错误'); toast.push('网络请求错误');
}); });
} }
// -----------------------------
// 组件变量 & 函数工具
/**渲染数据列表*/
let List = [];
/**渲染 & 更新视图 /**渲染 & 更新视图
* @param data JSON数据 * @param data JSON数据
*/ */
...@@ -80,19 +79,39 @@ ...@@ -80,19 +79,39 @@
* @param tag TAG * @param tag TAG
*/ */
function searchTag(tag) { function searchTag(tag) {
console.log(tag, encodeURIComponent(tag)); if (process.env.APP_ENV === 'dev') console.log(tag, encodeURIComponent(tag));
createFetch(searchTagRequest(tag), data => { createFetch(searchTagRequest(tag), data => {
console.log(data); if (process.env.APP_ENV === 'dev') console.log(data);
showList(data); showList(data);
}); });
} }
/**获取封面图
* @param folder 文件夹路径
*/
function getCover(folder) {
// const jsonLink = $_env + '/' + folder.substring(2) + '/rpg_info/info.json';
// createFetch({ url: jsonLink, params: { method: 'GET' } }, data => {
// console.log(data);
// });
// FIXME: 隐患 -> 可能是 1.png 1.webpage 之类的...
return $_env + '/' + folder.substring(2) + '/rpg_info/1.jpg';
}
/**获取 info.json
* @param folder 文件夹路径
*/
function getFolder(folder) {
return $_env + '/' + folder.substring(2) + '/rpg_info/';
}
// ----------------------------- // -----------------------------
// NOTE: 初始化执行 -> 考虑用 onMount // NOTE: 初始化执行 -> 考虑用 onMount
// 初始化请求 -> 拉取全部 // 初始化请求 -> 拉取全部
createFetch(getContentsRequest, data => { createFetch(getContentsRequest, data => {
console.log(data); if (process.env.APP_ENV === 'dev') console.log(data);
showList(data); showList(data);
}); });
</script> </script>
...@@ -104,7 +123,8 @@ ...@@ -104,7 +123,8 @@
<Card <Card
title={item.cn_name} title={item.cn_name}
sub_title={item.jp_name} sub_title={item.jp_name}
cover={$_env + '/' + item.folder.substring(2) + '/rpg_info/1.jpg' ?? ''} cover={getCover(item.folder)}
folder={getFolder(item.folder)}
language={item.category} language={item.category}
raw_tags={item.tags} raw_tags={item.tags}
p_searchTag={searchTag} p_searchTag={searchTag}
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
export let sub_title; export let sub_title;
/**父属性: 封面图片链接*/ /**父属性: 封面图片链接*/
export let cover; export let cover;
/**父属性: 路径*/
export let folder;
/**父属性: 语言分类*/ /**父属性: 语言分类*/
export let language; export let language;
/**父属性: TAG文本*/ /**父属性: TAG文本*/
...@@ -22,8 +24,20 @@ ...@@ -22,8 +24,20 @@
tags = raw_tags.slice(1, raw_tags.length - 1).split('|'); tags = raw_tags.slice(1, raw_tags.length - 1).split('|');
} }
// // 图片错误 trigger
let error = false; let _picError = false;
/**TODO: 显示所有缩略图*/
function getInfoPics() {
console.log(folder);
fetch(folder + '/info.json', { method: 'GET' })
.then(response => response.json())
.then(data => {
console.log(data);
// window.open(folder + data[1]);
});
}
</script> </script>
<div class="card w-80 bg-primary text-primary-content shadow-xl"> <div class="card w-80 bg-primary text-primary-content shadow-xl">
...@@ -32,11 +46,13 @@ ...@@ -32,11 +46,13 @@
<img <img
src={cover ?? '/favicon.ico'} src={cover ?? '/favicon.ico'}
alt={title ?? 'default alt'} alt={title ?? 'default alt'}
style={error ? 'height: 240px; width: 320px;' : ''} style={_picError ? 'height: 240px; width: 320px;' : ''}
on:error={() => { on:error={() => {
cover = '/favicon.ico'; cover = '/favicon.ico';
error = true; _picError = true;
}} }}
on:click={getInfoPics}
on:keypress={() => {}}
/> />
</figure> </figure>
<div class="card-body"> <div class="card-body">
...@@ -44,9 +60,9 @@ ...@@ -44,9 +60,9 @@
<!-- NOTE: 游戏类别 --> <!-- NOTE: 游戏类别 -->
<div class="badge badge-secondary m-auto" style="height: inherit;line-height: inherit;">{language ?? '示例'}</div> <div class="badge badge-secondary m-auto" style="height: inherit;line-height: inherit;">{language ?? '示例'}</div>
<!-- NOTE: 游戏名称 --> <!-- NOTE: 游戏名称 -->
{title ?? 'default title'} {title ?? '无中文名称'}
</h2> </h2>
<p>{sub_title ?? 'default sub_title'}</p> <p>{sub_title ?? '无日文名称'}</p>
<!-- NOTE: tags --> <!-- NOTE: tags -->
<!-- {#if raw_tags} <!-- {#if raw_tags}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment