更新若干功能
This commit is contained in:
@@ -6,6 +6,7 @@ use App\BaseApp\BaseWxService;
|
||||
use App\Models\business\WxTemplateModel;
|
||||
use App\Models\business\WxUserModel;
|
||||
use App\Models\WxAppModel;
|
||||
use App\Service\business\WxCardSchemeService;
|
||||
use App\Service\business\WxTemplatePresetService;
|
||||
use App\Service\business\WxTemplateSchemaService;
|
||||
|
||||
@@ -68,32 +69,88 @@ class WxThemeService extends BaseWxService
|
||||
$preset = WxTemplatePresetService::getInstance()->all()[0] ?? [];
|
||||
$tokens = $preset['tokens'] ?? [];
|
||||
$layout = $preset['layout'] ?? [];
|
||||
return [
|
||||
'code' => (string) ($preset['code'] ?? 'lux-champagne'),
|
||||
'name' => (string) ($preset['name'] ?? '轻奢·香槟金'),
|
||||
'style_tag' => (string) ($preset['style_tag'] ?? '轻奢'),
|
||||
'version' => 0,
|
||||
'tokens' => $tokens,
|
||||
'layout' => $layout,
|
||||
'css_vars' => $schema->toCssVariables($tokens),
|
||||
'fallback' => true,
|
||||
];
|
||||
return $this->packTheme(
|
||||
(string) ($preset['code'] ?? 'lux-champagne'),
|
||||
(string) ($preset['name'] ?? '轻奢·香槟金'),
|
||||
(string) ($preset['style_tag'] ?? '轻奢'),
|
||||
0,
|
||||
$tokens,
|
||||
$layout,
|
||||
$schema,
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
$template = $template->toArray();
|
||||
$tokens = is_array($template['tokens']) ? $template['tokens'] : [];
|
||||
$layout = is_array($template['layout']) ? $template['layout'] : [];
|
||||
return $this->packTheme(
|
||||
(string) $template['code'],
|
||||
(string) $template['name'],
|
||||
(string) $template['style_tag'],
|
||||
(int) $template['version'],
|
||||
$tokens,
|
||||
$layout,
|
||||
$schema,
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 组装主题包:令牌 + 布局 + 本模板引用到的卡片方案
|
||||
*/
|
||||
private function packTheme(
|
||||
string $code,
|
||||
string $name,
|
||||
string $styleTag,
|
||||
int $version,
|
||||
array $tokens,
|
||||
array $layout,
|
||||
WxTemplateSchemaService $schema,
|
||||
bool $fallback,
|
||||
): array {
|
||||
return [
|
||||
'code' => (string) $template['code'],
|
||||
'name' => (string) $template['name'],
|
||||
'style_tag' => (string) $template['style_tag'],
|
||||
'version' => (int) $template['version'],
|
||||
'code' => $code,
|
||||
'name' => $name,
|
||||
'style_tag' => $styleTag,
|
||||
'version' => $version,
|
||||
'tokens' => $tokens,
|
||||
'layout' => is_array($template['layout']) ? $template['layout'] : [],
|
||||
'layout' => $layout,
|
||||
'css_vars' => $schema->toCssVariables($tokens),
|
||||
'fallback' => false,
|
||||
'card_schemes' => WxCardSchemeService::mapByCodes($this->collectSchemeCodes($layout)),
|
||||
'features' => [
|
||||
'package_enabled' => WxAppService::getInstance()->packageEnabled(),
|
||||
],
|
||||
'fallback' => $fallback,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 从根 card_scheme、页级 pages.*.card_scheme、区块 props.card_scheme 收集引用
|
||||
*
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function collectSchemeCodes(array $layout): array
|
||||
{
|
||||
$codes = [];
|
||||
if (!empty($layout['card_scheme'])) {
|
||||
$codes[] = (string) $layout['card_scheme'];
|
||||
}
|
||||
foreach ((array) ($layout['pages'] ?? []) as $page) {
|
||||
$pageScheme = (string) ($page['card_scheme'] ?? '');
|
||||
if ($pageScheme !== '') {
|
||||
$codes[] = $pageScheme;
|
||||
}
|
||||
foreach ((array) ($page['sections'] ?? []) as $section) {
|
||||
$code = (string) ($section['props']['card_scheme'] ?? '');
|
||||
if ($code !== '') {
|
||||
$codes[] = $code;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $codes;
|
||||
}
|
||||
|
||||
/**
|
||||
* 可选风格列表,用于小程序里让用户自己换肤
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user