|
|
@@ -616,176 +616,6 @@ class ClientService implements ClientServiceInterface
|
|
|
}
|
|
|
|
|
|
|
|
|
- public function indexData1(array $data): array
|
|
|
- {
|
|
|
- $time1 = microtime(true);
|
|
|
- // 解析模板数据
|
|
|
- $templateData = json_decode($data['template'], true);
|
|
|
- $website_id = $templateData['base']['website_id'] ?? 2;
|
|
|
- $componentList = $templateData['template']['index'][0]['componentList'];
|
|
|
-
|
|
|
- // 1️⃣ 获取网站分类信息
|
|
|
- $websiteInfo = Db::table('website_category')
|
|
|
- ->where('website_id', $website_id)
|
|
|
- ->get()
|
|
|
- ->toArray();
|
|
|
-
|
|
|
- // 构建索引和拼音映射
|
|
|
- $websiteInfoIndexed = array_column($websiteInfo, null, 'category_id');
|
|
|
- $categoryIds = array_column($websiteInfo, 'category_id');
|
|
|
- $aliasPinyins = array_column($websiteInfo, 'aLIas_pinyin');
|
|
|
- $cat_arr = array_combine($categoryIds, $aliasPinyins);
|
|
|
-
|
|
|
- // 构建 catiall 和 cat_1st_arr
|
|
|
- $catiall = [];
|
|
|
- $cat_1st_arr = [];
|
|
|
-
|
|
|
- foreach ($websiteInfo as $item) {
|
|
|
- $arrId = json_decode($item->category_arr_id);
|
|
|
- $pinyin_str = implode('/', array_map(fn($id) => $cat_arr[$id], $arrId));
|
|
|
- $pinyin_str = rtrim($pinyin_str, '/');
|
|
|
-
|
|
|
- $catiall[$item->category_id][] = $pinyin_str;
|
|
|
- $websiteInfoIndexed[$item->category_id]->pinyin = $pinyin_str;
|
|
|
-
|
|
|
- if ($item->pid == 0) {
|
|
|
- $cat_1st_arr[$item->category_id] = [];
|
|
|
- } else {
|
|
|
- $cat_1st_arr[$item->pid][] = $item->category_id;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 2️⃣ 提前聚合所有需要查询的 category_id 和限制参数
|
|
|
- $allCatIds = [];
|
|
|
- $imgLimits = [];
|
|
|
- $txtLimits = [];
|
|
|
- $childImgLimits = [];
|
|
|
- $childTxtLimits = [];
|
|
|
-
|
|
|
- foreach ($componentList as $item) {
|
|
|
- $componentData = $item['componentData'];
|
|
|
- $category_id = $componentData['category_id'] ?? 0;
|
|
|
-
|
|
|
- if ($category_id > 0) {
|
|
|
- $allCatIds[] = $category_id;
|
|
|
- $imgLimits[$category_id] = $componentData['imgSize'] ?? 0;
|
|
|
- $txtLimits[$category_id] = $componentData['textSize'] ?? 0;
|
|
|
-
|
|
|
- if (!empty($cat_1st_arr[$category_id])) {
|
|
|
- $allCatIds = array_merge($allCatIds, $cat_1st_arr[$category_id]);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 子级
|
|
|
- $child = $componentData['child'] ?? null;
|
|
|
- if ($child && isset($child['id']) && $child['id'] > 0) {
|
|
|
- $child_id = $child['id'];
|
|
|
- $childImgLimits[$child_id] = $child['imgSize'] ?? 0;
|
|
|
- $childTxtLimits[$child_id] = $child['textSize'] ?? 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $allCatIds = array_unique(array_filter($allCatIds));
|
|
|
-
|
|
|
- // 3️⃣ 一次性查询所有 article 数据
|
|
|
- $allArticles = Db::table('article')
|
|
|
- ->whereIn('catid', $allCatIds)
|
|
|
- ->where('status', 1)
|
|
|
- ->get()
|
|
|
- ->toArray();
|
|
|
-
|
|
|
- // 构建按 imgurl 分类的文章集合
|
|
|
- $articlesByCat = ['img' => [], 'txt' => []];
|
|
|
- foreach ($allArticles as $article) {
|
|
|
- if (!empty($article->imgurl)) {
|
|
|
- $articlesByCat['img'][$article->catid][] = $article;
|
|
|
- } else {
|
|
|
- $articlesByCat['txt'][$article->catid][] = $article;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 4️⃣ 使用协程并发处理每个组件
|
|
|
- $results = [];
|
|
|
-
|
|
|
- foreach ($componentList as $key => $value) {
|
|
|
- $componentKey = $key;
|
|
|
- $componentData = $value['componentData'];
|
|
|
-
|
|
|
- Coroutine::create(function () use (&$results, $componentKey, $componentData, $websiteInfoIndexed, $cat_1st_arr, $catiall, $articlesByCat, $imgLimits, $txtLimits, $childImgLimits, $childTxtLimits) {
|
|
|
- $result = [];
|
|
|
-
|
|
|
- $category_id = $componentData['category_id'] ?? 0;
|
|
|
- $imgLimit = $imgLimits[$category_id] ?? 0;
|
|
|
- $txtLimit = $txtLimits[$category_id] ?? 0;
|
|
|
-
|
|
|
- if ($category_id > 0) {
|
|
|
- // 图文数据
|
|
|
- $imgArticles = array_slice($articlesByCat['img'][$category_id] ?? [], 0, $imgLimit);
|
|
|
- foreach ($imgArticles as &$v) {
|
|
|
- $v->pinyin = $catiall[$v->catid][0] ?? '';
|
|
|
- }
|
|
|
-
|
|
|
- // 纯文字数据
|
|
|
- $textArticles = array_slice($articlesByCat['txt'][$category_id] ?? [], 0, $txtLimit);
|
|
|
- foreach ($textArticles as &$v) {
|
|
|
- $v->pinyin = $catiall[$v->catid][0] ?? '';
|
|
|
- }
|
|
|
-
|
|
|
- $result['imgnum'] = $imgArticles;
|
|
|
- $result['textnum'] = $textArticles;
|
|
|
- $result['alias'] = $websiteInfoIndexed[$category_id]['alias'] ?? '';
|
|
|
- $result['pinyin'] = $websiteInfoIndexed[$category_id]['pinyin'] ?? '';
|
|
|
- $result['category_id'] = $category_id;
|
|
|
- }
|
|
|
-
|
|
|
- // 子级处理
|
|
|
- $child = $componentData['child'] ?? null;
|
|
|
- if ($child && isset($child['id']) && $child['id'] > 0) {
|
|
|
- $child_id = $child['id'];
|
|
|
- $c_imgLimit = $childImgLimits[$child_id] ?? 0;
|
|
|
- $c_txtLimit = $childTxtLimits[$child_id] ?? 0;
|
|
|
-
|
|
|
- $childImg = array_slice($articlesByCat['img'][$child_id] ?? [], 0, $c_imgLimit);
|
|
|
- foreach ($childImg as &$v) {
|
|
|
- $v->pinyin = $catiall[$v->catid][0] ?? '';
|
|
|
- }
|
|
|
-
|
|
|
- $childText = array_slice($articlesByCat['txt'][$child_id] ?? [], 0, $c_txtLimit);
|
|
|
- foreach ($childText as &$v) {
|
|
|
- $v->pinyin = $catiall[$v->catid][0] ?? '';
|
|
|
- }
|
|
|
-
|
|
|
- $result['child'] = [
|
|
|
- 'alias' => $websiteInfoIndexed[$child_id]['alias'] ?? '',
|
|
|
- 'pinyin' => $websiteInfoIndexed[$child_id]['pinyin'] ?? '',
|
|
|
- 'category_id' => $child_id,
|
|
|
- 'textnum' => $childText,
|
|
|
- 'imgnum' => $childImg,
|
|
|
- 'all_childcat' => array_map(fn($v) => $websiteInfoIndexed[$v], $cat_1st_arr[$category_id] ?? []),
|
|
|
- ];
|
|
|
- }
|
|
|
-
|
|
|
- $results[$componentKey] = $result;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // 等待所有协程完成(生产环境应使用 WaitGroup)
|
|
|
- usleep(200000); // 示例中简单等待
|
|
|
-
|
|
|
- // 5️⃣ 回填结果到 componentList
|
|
|
- foreach ($componentList as $key => &$component) {
|
|
|
- $componentData = $component['componentData'];
|
|
|
- $category_id = $componentData['category_id'] ?? 0;
|
|
|
-
|
|
|
- if (isset($results[$key])) {
|
|
|
- $component['componentData']['data'] = $results[$key];
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 6️⃣ 返回最终数据
|
|
|
- $templateData['template']['index'][0]['componentList'] = $componentList;
|
|
|
- return $templateData;
|
|
|
- }
|
|
|
public function addWeb($data)
|
|
|
{
|
|
|
$result = WebsiteTemplate::insertGetId($data);
|
|
|
@@ -1010,186 +840,7 @@ class ClientService implements ClientServiceInterface
|
|
|
}
|
|
|
}
|
|
|
private function bt($data) {}
|
|
|
- public function updateWebConfig1($data)
|
|
|
- {
|
|
|
- // 先根据
|
|
|
- // 根据是否测试环境配置不同 的vue项目的 配置文件
|
|
|
- //获取根目录下 yuan 源代码,开始处理
|
|
|
- //获取目前目录,获取根目录
|
|
|
- $root = dirname(dirname(__DIR__));
|
|
|
- $yuan = $root . '/yuan';
|
|
|
- //取出envAPP_ENV=dev
|
|
|
- $APP_ENV = env('APP_ENV');
|
|
|
- switch ($APP_ENV) {
|
|
|
- case 'dev':
|
|
|
- $file = $yuan . '/plugins/category.ts';
|
|
|
- break;
|
|
|
- case 'prod':
|
|
|
- $file = $yuan . '/plugins/category.ts';
|
|
|
- break;
|
|
|
- default:
|
|
|
- $file = $yuan . '/plugins/category.ts';
|
|
|
- }
|
|
|
- //处理文件plugins\category.ts
|
|
|
- //找到 export default defineNuxtPlugin((nuxtApp) => {,处理到文件结尾
|
|
|
- /*
|
|
|
- export default defineNuxtPlugin((nuxtApp) => {
|
|
|
- //master 环境
|
|
|
- nuxtApp.provide('pageNav', navMaster)
|
|
|
- //pre 环境
|
|
|
- // nuxtApp.provide('pageNav', navPre)
|
|
|
- })
|
|
|
- */
|
|
|
- if (0 == 1) {
|
|
|
- $content = file_get_contents($file);
|
|
|
- $content = str_replace("nuxtApp.provide('pageNav', navPre)", "//nuxtApp.provide('pageNav', navPre)", $content);
|
|
|
- $content = str_replace("//nuxtApp.provide('pageNav', navMaster)", "nuxtApp.provide('pageNav', navMaster)", $content);
|
|
|
- //写入文件
|
|
|
- $res = file_put_contents($file, $content);
|
|
|
- var_dump('已经处理/plugins/category.ts');
|
|
|
- //处理文件\plugins\globals.js
|
|
|
- $file = $yuan . '/plugins/globals.js';
|
|
|
- $content = file_get_contents($file);
|
|
|
- // 1️⃣ 将没有注释的 nuxtApp.provide(...) 行加上注释
|
|
|
- $content = preg_replace('/^(?!\s*\/\/)(?=.*nuxtApp\.provide)/m', '// ', $content);
|
|
|
-
|
|
|
- // 2️⃣ 找到 "//乡村网正式环境" 下面的注释行并取消注释
|
|
|
- $lines = explode("\n", $content);
|
|
|
- $output = [];
|
|
|
- $foundSection = false;
|
|
|
-
|
|
|
- foreach ($lines as $line) {
|
|
|
- // 判断是否进入目标区域
|
|
|
- if (preg_match('/\/\/乡村网正式环境/', $line)) {
|
|
|
- $foundSection = true;
|
|
|
- $output[] = $line;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 在目标区域内,去掉注释
|
|
|
- if ($foundSection && preg_match('/^\s*\/\/\s*(nuxtApp\.provide)/', $line, $matches)) {
|
|
|
- $output[] = preg_replace('/^\s*\/\/\s*/', '', $line, 1);
|
|
|
- } else {
|
|
|
- // 如果遇到下一个注释块或空白行,结束当前处理
|
|
|
- if ($foundSection && preg_match('/^\s*$/', $line)) {
|
|
|
- $foundSection = false;
|
|
|
- }
|
|
|
- $output[] = $line;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 合并回字符串
|
|
|
- $newContent = implode("\n", $output);
|
|
|
- // 写入文件
|
|
|
- $res1 = file_put_contents($file, $newContent);
|
|
|
- var_dump($res1, '已经处理/plugins/globals.js');
|
|
|
-
|
|
|
- //处理文件\plugins\request.js
|
|
|
- $file = $yuan . '/plugins/request.js';
|
|
|
- $content = file_get_contents($file);
|
|
|
- $lines = explode("\n", $content);
|
|
|
|
|
|
- $in_prod = false;
|
|
|
- $in_pre = false;
|
|
|
-
|
|
|
- for ($i = 0; $i < count($lines); $i++) {
|
|
|
- $line = $lines[$i];
|
|
|
-
|
|
|
- // 匹配 "//正式环境"
|
|
|
- if (preg_match('/\/\/正式环境/', $line)) {
|
|
|
- $in_prod = true;
|
|
|
- $in_pre = false;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 匹配 "//pre环境"
|
|
|
- if (preg_match('/\/\/pre环境/', $line)) {
|
|
|
- $in_pre = true;
|
|
|
- $in_prod = false;
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- // 处理正式环境下的两行:去注释
|
|
|
- if ($in_prod && $i + 0 <= count($lines) && $i + 1 <= count($lines)) {
|
|
|
- for ($j = $i + 0; $j <= $i + 1; $j++) {
|
|
|
- if (isset($lines[$j])) {
|
|
|
- $lines[$j] = preg_replace('/^\s*\/\/\s*/', '', $lines[$j]);
|
|
|
- }
|
|
|
- }
|
|
|
- $in_prod = false; // 只处理一次
|
|
|
- }
|
|
|
-
|
|
|
- // 处理 pre 环境下的两行:添加注释
|
|
|
- if ($in_pre && $i + 0 <= count($lines) && $i + 1 <= count($lines)) {
|
|
|
- for ($j = $i + 1; $j <= $i + 2; $j++) {
|
|
|
- if (isset($lines[$j]) && !preg_match('/^\s*\/\//', $lines[$j])) {
|
|
|
- // $lines[$j] = '// ' . $lines[$j];
|
|
|
- }
|
|
|
- }
|
|
|
- $in_pre = false; // 只处理一次
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // 写回文件
|
|
|
- $res2 = file_put_contents($file, implode("\n", $lines));
|
|
|
- var_dump($res2, '已经处理/plugins/request.js');
|
|
|
- echo "✅ 环境配置切换完成!";
|
|
|
-
|
|
|
-
|
|
|
- //第三步 定位到yuan目录,执行 npm run build 生成output目录
|
|
|
- chdir($yuan);
|
|
|
- $APP_ENV = env('APP_ENV');
|
|
|
- $res3 = exec("npm run build");
|
|
|
- var_dump($res, '执行 npm run build');
|
|
|
- echo "✅ 构建完成!";
|
|
|
-
|
|
|
- //第四步
|
|
|
- //修改 .output\server\chunks\routes\index.mjs ,
|
|
|
- // 根据网站的id的port更改端口
|
|
|
- //第五步
|
|
|
- //x
|
|
|
-
|
|
|
-
|
|
|
- $file4 = $yuan . '/.output/server/chunks/routes/index.mjs';
|
|
|
- $content = file_get_contents($file4);
|
|
|
- // 使用正则将 "destr(...) || 3e3" 替换为 "destr(...) || 9000"
|
|
|
- $content = preg_replace(
|
|
|
- '/(destr$[^)]+$$\s*\|\|\s*)3e3/i',
|
|
|
- '$19000',
|
|
|
- $content
|
|
|
- );
|
|
|
-
|
|
|
- // 写回文件
|
|
|
- file_put_contents($file, $content);
|
|
|
- }
|
|
|
- //第六步 yuan压缩成压缩包,复制到/hyperf-skeleton/web1/,解压
|
|
|
- $dir_yuan = $yuan . '/.output/';
|
|
|
- // 移动到web 没有就创建
|
|
|
- $dir_web = '/hyperf-skeleton/' . '/web1/';
|
|
|
- if (!is_dir($dir_web)) {
|
|
|
- mkdir($dir_web, 0755, true);
|
|
|
- }
|
|
|
- $fs = new Filesystem();
|
|
|
-
|
|
|
- $fs->rename($dir_yuan, $dir_web . 'output', true);
|
|
|
- var_dump('已经移动到/hyperf-skeleton/web1/output');
|
|
|
- $result = [
|
|
|
- 'res' => $res,
|
|
|
- 'res1' => $res1,
|
|
|
- 'res2' => $res2,
|
|
|
- 'res3' => $res3,
|
|
|
-
|
|
|
- 'root' => $root,
|
|
|
- 'yuan' => $yuan,
|
|
|
- 'APP_ENV' => $APP_ENV,
|
|
|
- 'website_id' => $data['website_id'],
|
|
|
- ];
|
|
|
- if ($result) {
|
|
|
- return Result::success($result);
|
|
|
- } else {
|
|
|
- return Result::error('更新配置失败');
|
|
|
- }
|
|
|
- }
|
|
|
public function updateWebOutput($data)
|
|
|
{
|
|
|
|