mirror of
https://github.com/ZZZure/ZZZ-Plugin.git
synced 2025-12-16 13:17:32 +00:00
render
This commit is contained in:
parent
e166e0e185
commit
d0e73ff00c
12 changed files with 105 additions and 31 deletions
|
|
@ -1,9 +1,8 @@
|
||||||
import { ZZZPlugin } from '../lib/plugin.js';
|
import { ZZZPlugin } from '../lib/plugin.js';
|
||||||
import render from '../lib/render.js';
|
|
||||||
import { rulePrefix } from '../lib/common.js';
|
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { ZZZChallenge } from '../model/abyss.js';
|
import { ZZZChallenge } from '../model/abyss.js';
|
||||||
|
import { rulePrefix } from '../lib/common.js';
|
||||||
|
|
||||||
export class Abyss extends ZZZPlugin {
|
export class Abyss extends ZZZPlugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -42,6 +41,6 @@ export class Abyss extends ZZZPlugin {
|
||||||
const finalData = {
|
const finalData = {
|
||||||
abyss,
|
abyss,
|
||||||
};
|
};
|
||||||
await render(this.e, 'abyss/index.html', finalData, this);
|
await this.render('abyss/index.html', finalData, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import { ZZZPlugin } from '../lib/plugin.js';
|
import { ZZZPlugin } from '../lib/plugin.js';
|
||||||
import render from '../lib/render.js';
|
|
||||||
import { rulePrefix } from '../lib/common.js';
|
|
||||||
import { ZZZIndexResp } from '../model/index.js';
|
import { ZZZIndexResp } from '../model/index.js';
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { rulePrefix } from '../lib/common.js';
|
||||||
|
|
||||||
export class Card extends ZZZPlugin {
|
export class Card extends ZZZPlugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -46,6 +45,6 @@ export class Card extends ZZZPlugin {
|
||||||
const data = {
|
const data = {
|
||||||
card: finalIndexData,
|
card: finalIndexData,
|
||||||
};
|
};
|
||||||
await render(this.e, 'card/index.html', data);
|
await this.render('card/index.html', data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,4 @@
|
||||||
import { ZZZPlugin } from '../lib/plugin.js';
|
import { ZZZPlugin } from '../lib/plugin.js';
|
||||||
import render from '../lib/render.js';
|
|
||||||
import { rulePrefix } from '../lib/common.js';
|
|
||||||
import { getAuthKey } from '../lib/authkey.js';
|
import { getAuthKey } from '../lib/authkey.js';
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
@ -13,6 +11,7 @@ import {
|
||||||
getZZZGachaLogByAuthkey,
|
getZZZGachaLogByAuthkey,
|
||||||
} from '../lib/gacha.js';
|
} from '../lib/gacha.js';
|
||||||
import { getQueryVariable } from '../utils/network.js';
|
import { getQueryVariable } from '../utils/network.js';
|
||||||
|
import { rulePrefix } from '../lib/common.js';
|
||||||
|
|
||||||
export class GachaLog extends ZZZPlugin {
|
export class GachaLog extends ZZZPlugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -240,7 +239,7 @@ export class GachaLog extends ZZZPlugin {
|
||||||
const result = {
|
const result = {
|
||||||
data,
|
data,
|
||||||
};
|
};
|
||||||
await render(this.e, 'gachalog/index.html', result);
|
await this.render('gachalog/index.html', result);
|
||||||
}
|
}
|
||||||
async getGachaLink() {
|
async getGachaLink() {
|
||||||
if (!this.e.isPrivate || this.e.isGroup) {
|
if (!this.e.isPrivate || this.e.isGroup) {
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ import fetch from 'node-fetch';
|
||||||
import lodash from 'lodash';
|
import lodash from 'lodash';
|
||||||
import common from '../../../lib/common/common.js';
|
import common from '../../../lib/common/common.js';
|
||||||
import { ZZZPlugin } from '../lib/plugin.js';
|
import { ZZZPlugin } from '../lib/plugin.js';
|
||||||
import { rulePrefix } from '../lib/common.js';
|
|
||||||
import { imageResourcesPath } from '../lib/path.js';
|
import { imageResourcesPath } from '../lib/path.js';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import { downloadFile } from '../lib/download.js';
|
import { downloadFile } from '../lib/download.js';
|
||||||
import { char } from '../lib/convert.js';
|
import { char } from '../lib/convert.js';
|
||||||
import guides from '../lib/guides.js';
|
import guides from '../lib/guides.js';
|
||||||
|
import { rulePrefix } from '../lib/common.js';
|
||||||
|
|
||||||
const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides');
|
const ZZZ_GUIDES_PATH = path.join(imageResourcesPath, 'guides');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { ZZZPlugin } from '../lib/plugin.js';
|
|
||||||
import { rulePrefix } from '../lib/common.js';
|
import { rulePrefix } from '../lib/common.js';
|
||||||
import render from '../lib/render.js';
|
import { ZZZPlugin } from '../lib/plugin.js';
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
/**
|
/**
|
||||||
|
|
@ -335,12 +334,12 @@ export class Help extends ZZZPlugin {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
await render(this.e, 'help/index.html', {
|
await this.render('help/index.html', {
|
||||||
helpData: _helpData,
|
helpData: _helpData,
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
await render(this.e, 'help/index.html', {
|
await this.render('help/index.html', {
|
||||||
helpData,
|
helpData,
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { ZZZPlugin } from '../lib/plugin.js';
|
import { ZZZPlugin } from '../lib/plugin.js';
|
||||||
import { rulePrefix } from '../lib/common.js';
|
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import manage from './manage/index.js';
|
import manage from './manage/index.js';
|
||||||
|
import { rulePrefix } from '../lib/common.js';
|
||||||
|
|
||||||
export class Panel extends ZZZPlugin {
|
export class Panel extends ZZZPlugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,10 @@
|
||||||
import version from '../../lib/version.js';
|
import version from '../../lib/version.js';
|
||||||
import render from '../../lib/render.js';
|
|
||||||
import { ZZZUpdate } from '../../lib/update.js';
|
import { ZZZUpdate } from '../../lib/update.js';
|
||||||
import { pluginName } from '../../lib/path.js';
|
import { pluginName } from '../../lib/path.js';
|
||||||
|
|
||||||
export async function getChangeLog() {
|
export async function getChangeLog() {
|
||||||
const versionData = version.changelogs;
|
const versionData = version.changelogs;
|
||||||
await render(this.e, 'help/version.html', {
|
await this.render('help/version.html', {
|
||||||
versionData,
|
versionData,
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -19,7 +18,7 @@ export async function getCommitLog() {
|
||||||
if (updatePlugin.getPlugin(pluginName)) {
|
if (updatePlugin.getPlugin(pluginName)) {
|
||||||
try {
|
try {
|
||||||
const commitData = await updatePlugin.getZZZAllLog();
|
const commitData = await updatePlugin.getZZZAllLog();
|
||||||
await render(this.e, 'help/commit.html', {
|
await this.render('help/commit.html', {
|
||||||
commitData,
|
commitData,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -41,7 +40,7 @@ export async function hasUpdate() {
|
||||||
const result = await updatePlugin.hasUpdate();
|
const result = await updatePlugin.hasUpdate();
|
||||||
if (result.hasUpdate) {
|
if (result.hasUpdate) {
|
||||||
await this.reply(`[${pluginName}]有${result.logs.length || 1}个更新`);
|
await this.reply(`[${pluginName}]有${result.logs.length || 1}个更新`);
|
||||||
await render(this.e, 'help/commit.html', {
|
await this.render('help/commit.html', {
|
||||||
commitData: result.logs,
|
commitData: result.logs,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import { ZZZPlugin } from '../lib/plugin.js';
|
import { ZZZPlugin } from '../lib/plugin.js';
|
||||||
import render from '../lib/render.js';
|
|
||||||
import { ZZZNoteResp } from '../model/note.js';
|
import { ZZZNoteResp } from '../model/note.js';
|
||||||
import { rulePrefix } from '../lib/common.js';
|
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { rulePrefix } from '../lib/common.js';
|
||||||
|
|
||||||
export class Note extends ZZZPlugin {
|
export class Note extends ZZZPlugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -29,6 +28,6 @@ export class Note extends ZZZPlugin {
|
||||||
const finalData = {
|
const finalData = {
|
||||||
note: noteData,
|
note: noteData,
|
||||||
};
|
};
|
||||||
await render(this.e, 'note/index.html', finalData);
|
await this.render('note/index.html', finalData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
import { ZZZPlugin } from '../lib/plugin.js';
|
import { ZZZPlugin } from '../lib/plugin.js';
|
||||||
import render from '../lib/render.js';
|
|
||||||
import { rulePrefix } from '../lib/common.js';
|
|
||||||
import { getPanelList, refreshPanel, getPanel } from '../lib/avatar.js';
|
import { getPanelList, refreshPanel, getPanel } from '../lib/avatar.js';
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { rulePrefix } from '../lib/common.js';
|
||||||
|
|
||||||
export class Panel extends ZZZPlugin {
|
export class Panel extends ZZZPlugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
@ -64,7 +63,7 @@ export class Panel extends ZZZPlugin {
|
||||||
newChar: newChar.length,
|
newChar: newChar.length,
|
||||||
list: result,
|
list: result,
|
||||||
};
|
};
|
||||||
await render(this.e, 'panel/refresh.html', finalData);
|
await this.render('panel/refresh.html', finalData);
|
||||||
}
|
}
|
||||||
async getCharPanelList() {
|
async getCharPanelList() {
|
||||||
const uid = await this.getUID();
|
const uid = await this.getUID();
|
||||||
|
|
@ -87,7 +86,7 @@ export class Panel extends ZZZPlugin {
|
||||||
count: result?.length || 0,
|
count: result?.length || 0,
|
||||||
list: result,
|
list: result,
|
||||||
};
|
};
|
||||||
await render(this.e, 'panel/list.html', finalData);
|
await this.render('panel/list.html', finalData);
|
||||||
}
|
}
|
||||||
async getCharPanel() {
|
async getCharPanel() {
|
||||||
const uid = await this.getUID();
|
const uid = await this.getUID();
|
||||||
|
|
@ -111,7 +110,7 @@ export class Panel extends ZZZPlugin {
|
||||||
uid: uid,
|
uid: uid,
|
||||||
charData: data,
|
charData: data,
|
||||||
};
|
};
|
||||||
const image = await render(this.e, 'panel/card.html', finalData, {
|
const image = await this.render('panel/card.html', finalData, {
|
||||||
retType: 'base64',
|
retType: 'base64',
|
||||||
});
|
});
|
||||||
const res = await this.reply(image);
|
const res = await this.reply(image);
|
||||||
|
|
@ -164,7 +163,7 @@ export class Panel extends ZZZPlugin {
|
||||||
general,
|
general,
|
||||||
list: result,
|
list: result,
|
||||||
};
|
};
|
||||||
await render(this.e, 'proficiency/index.html', finalData);
|
await this.render('proficiency/index.html', finalData);
|
||||||
}
|
}
|
||||||
async getCharOriImage() {
|
async getCharOriImage() {
|
||||||
let source;
|
let source;
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,9 @@
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { rulePrefix } from '../lib/common.js';
|
|
||||||
import { pluginName } from '../lib/path.js';
|
import { pluginName } from '../lib/path.js';
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import { ZZZUpdate } from '../lib/update.js';
|
import { ZZZUpdate } from '../lib/update.js';
|
||||||
import config from '../../../lib/config/config.js';
|
import config from '../../../lib/config/config.js';
|
||||||
|
import { rulePrefix } from '../lib/common.js';
|
||||||
|
|
||||||
export class update extends plugin {
|
export class update extends plugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { ZZZPlugin } from '../lib/plugin.js';
|
import { ZZZPlugin } from '../lib/plugin.js';
|
||||||
import { rulePrefix } from '../lib/common.js';
|
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import common from '../../../lib/common/common.js';
|
import common from '../../../lib/common/common.js';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { rulePrefix } from '../lib/common.js';
|
||||||
|
|
||||||
export class Panel extends ZZZPlugin {
|
export class Panel extends ZZZPlugin {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,9 @@ import _ from 'lodash';
|
||||||
import NoteUser from '../../genshin/model/mys/NoteUser.js';
|
import NoteUser from '../../genshin/model/mys/NoteUser.js';
|
||||||
import settings from '../lib/settings.js';
|
import settings from '../lib/settings.js';
|
||||||
import request from '../utils/request.js';
|
import request from '../utils/request.js';
|
||||||
|
import path from 'path';
|
||||||
|
import { pluginName, resourcesPath } from './path.js';
|
||||||
|
import version from './version.js';
|
||||||
export class ZZZPlugin extends plugin {
|
export class ZZZPlugin extends plugin {
|
||||||
/**
|
/**
|
||||||
* 获取用户 UID(如果需要同时获取API,可以直接调用 getAPI)
|
* 获取用户 UID(如果需要同时获取API,可以直接调用 getAPI)
|
||||||
|
|
@ -196,4 +198,83 @@ export class ZZZPlugin extends plugin {
|
||||||
// 返回数据
|
// 返回数据
|
||||||
return userData;
|
return userData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 渲染函数
|
||||||
|
* @param {string} renderPath 渲染路径
|
||||||
|
* @param {object} renderData 渲染数据
|
||||||
|
* @param {object} cfg 配置
|
||||||
|
* @returns {Promise<any>}
|
||||||
|
*/
|
||||||
|
render(renderPath, renderData = {}, cfg = {}) {
|
||||||
|
const e = this.e || cfg?.e;
|
||||||
|
// 判断是否存在e.runtime
|
||||||
|
if (!e.runtime) {
|
||||||
|
logger.error('未找到e.runtime,请升级至最新版Yunzai');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取渲染精度配置
|
||||||
|
const renderCfg = _.get(settings.getConfig('config'), 'render', {});
|
||||||
|
const scaleCfg = _.get(renderCfg, 'scale', 100);
|
||||||
|
// 计算配置缩放比例
|
||||||
|
const scaleCfgValue = Math.min(2, Math.max(0.5, scaleCfg / 100)) * 2;
|
||||||
|
// 将函数参数中的缩放比例与配置缩放比例相乘
|
||||||
|
const scale = (cfg?.scale || 1) * scaleCfgValue;
|
||||||
|
// 将缩放比例转换为style属性
|
||||||
|
const pct = `style='transform:scale(${scale})'`;
|
||||||
|
// 获取布局路径
|
||||||
|
const layoutPathFull = path.join(resourcesPath, 'common/layout/');
|
||||||
|
|
||||||
|
// 调用e.runtime.render方法渲染
|
||||||
|
return e.runtime.render(pluginName, renderPath, renderData, {
|
||||||
|
// 合并传入的配置
|
||||||
|
...cfg,
|
||||||
|
beforeRender({ data }) {
|
||||||
|
// 资源路径
|
||||||
|
const resPath = data.pluResPath;
|
||||||
|
// 布局路径
|
||||||
|
const layoutPath = data.pluResPath + 'common/layout/';
|
||||||
|
// 当前的渲染路径
|
||||||
|
const renderPathFull = data.pluResPath + renderPath.split('/')[0] + '/';
|
||||||
|
// 合并数据
|
||||||
|
return {
|
||||||
|
// 玩家信息
|
||||||
|
player: e?.playerCard?.player,
|
||||||
|
// 玩家头像
|
||||||
|
avatar: e?.playerCard?.avatar,
|
||||||
|
// 传入的数据
|
||||||
|
...data,
|
||||||
|
// 资源路径
|
||||||
|
_res_path: resPath,
|
||||||
|
// 布局路径
|
||||||
|
_layout_path: layoutPath,
|
||||||
|
// 默认布局路径
|
||||||
|
defaultLayout: path.join(layoutPathFull, 'index.html'),
|
||||||
|
// 系统配置
|
||||||
|
sys: {
|
||||||
|
// 缩放比例
|
||||||
|
scale: pct,
|
||||||
|
// 资源路径
|
||||||
|
resourcesPath: resPath,
|
||||||
|
// 当前渲染的路径
|
||||||
|
currentPath: renderPathFull,
|
||||||
|
/**
|
||||||
|
* 下面两个模块的作用在于,你可以在你的布局文件中使用这两个模块,就可以显示用户信息和特殊标题,使用方法如下:
|
||||||
|
* 1. 展示玩家信息:首先你要在查询的时候调用`this.getPlayerInfo()`,这样,玩家数据就会保存在`e.playerCard`中,然后你就可以在布局文件中使用`{{include sys.playerInfo}}`来展示玩家信息。
|
||||||
|
* 2. 展示特殊标题:你可以在布局文件中使用`<% include(sys.specialTitle, {en: 'PROPERTY' , cn: '属性' , count: 6 }) %>`来展示特殊标题,其中`count`为可选参数,默认为9。
|
||||||
|
*/
|
||||||
|
// 玩家信息模块
|
||||||
|
playerInfo: path.join(layoutPathFull, 'playerinfo.html'),
|
||||||
|
// 特殊标题模块
|
||||||
|
specialTitle: path.join(layoutPathFull, 'specialtitle.html'),
|
||||||
|
// 版权信息
|
||||||
|
copyright: `Created By ${version.name}<span class="version">${version.yunzai}</span> & ${pluginName}<span class="version">${version.version}</span>`,
|
||||||
|
// 版权信息(简化版)
|
||||||
|
createdby: `Created By <div class="highlight"><span>${pluginName}</span><div class="version">${version.version}</div></div> & Powered By <div class="highlight">ZZZure</div>`,
|
||||||
|
},
|
||||||
|
quality: 100,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue