|
@@ -10,10 +10,12 @@ use App\Model\Complaint;
|
|
|
use App\Model\JobEnum;
|
|
|
use App\Model\User;
|
|
|
use App\Model\webisitecategory;
|
|
|
+use App\Model\WebsiteTemplate;
|
|
|
use Hyperf\Coroutine\Coroutine;
|
|
|
use Hyperf\Redis\Redis;
|
|
|
use Hyperf\Di\Annotation\Inject;
|
|
|
-
|
|
|
+use function Hyperf\Support\env;
|
|
|
+use Symfony\Component\Filesystem\Filesystem;
|
|
|
|
|
|
#[RpcService(name: "ClientService", protocol: "jsonrpc-http", server: "jsonrpc-http")]
|
|
|
|
|
@@ -751,4 +753,280 @@ class ClientService implements ClientServiceInterface
|
|
|
$templateData['template']['index'][0]['componentList'] = $componentList;
|
|
|
return $templateData;
|
|
|
}
|
|
|
+ public function addWeb($data)
|
|
|
+ {
|
|
|
+ $result = WebsiteTemplate::insertGetId($data);
|
|
|
+ if ($result) {
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error('添加失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function deleteWeb($data)
|
|
|
+ {
|
|
|
+ $result = WebsiteTemplate::where('id', $data['id'])->delete();
|
|
|
+ if ($result) {
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error('删除失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function updateWeb($data)
|
|
|
+ {
|
|
|
+ $result = WebsiteTemplate::where('id', $data['id'])->update($data);
|
|
|
+ if ($result) {
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error('更新失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function getWebInfo($data)
|
|
|
+ {
|
|
|
+ $result = WebsiteTemplate::where('website_template.id', $data['id'])
|
|
|
+ ->leftJoin('website', 'website.id', '=', 'website_template.website_id')
|
|
|
+ ->select('website_template.*', 'website.website_name as website_name', 'website.website_url as website_url')
|
|
|
+ ->first();
|
|
|
+ return Result::success($result);
|
|
|
+ }
|
|
|
+ public function getWebList($data)
|
|
|
+ {
|
|
|
+ var_dump($data, 'data');
|
|
|
+ $where = [];
|
|
|
+ if (isset($data['website_name'])) {
|
|
|
+ $where[] = ['website.website_name', 'like', '%' . $data['website_name'] . '%'];
|
|
|
+ }
|
|
|
+ if (isset($data['status'])) {
|
|
|
+ $where[] = ['website_template.status', '=', $data['status']];
|
|
|
+ }
|
|
|
+ $result = WebsiteTemplate::where([])
|
|
|
+ ->where($where)
|
|
|
+ ->leftJoin('website', 'website.id', '=', 'website_template.website_id')
|
|
|
+ ->select('website_template.*', 'website.website_name as website_name', 'website.website_url as website_url')
|
|
|
+ ->get();
|
|
|
+ if ($result) {
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error('获取列表失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function updateWebConfig($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)
|
|
|
+ {
|
|
|
+ //根据源程序, 复制出来,更改配置文件,打包,
|
|
|
+ $result = WebsiteTemplate::where('id', $data['id'])->update($data);
|
|
|
+ if ($result) {
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error('更新输出失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function updateWebMove($data)
|
|
|
+ {
|
|
|
+
|
|
|
+ //更改到dir目录,
|
|
|
+ $result = WebsiteTemplate::where('id', $data['id'])->update($data);
|
|
|
+ if ($result) {
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error('更新移动失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function runWeb($data)
|
|
|
+ {
|
|
|
+ //运行网站, 先检查是否有配置文件, pm2启动
|
|
|
+ $result = WebsiteTemplate::where('id', $data['id'])->update($data);
|
|
|
+ if ($result) {
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error('运行失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public function stopWeb($data)
|
|
|
+ {
|
|
|
+ $result = WebsiteTemplate::where('id', $data['id'])->update($data);
|
|
|
+ if ($result) {
|
|
|
+ return Result::success($result);
|
|
|
+ } else {
|
|
|
+ return Result::error('停止失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|