ai-code.vue 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448
  1. <template>
  2. <div class="ai-code">
  3. <div class="bg">
  4. <div class="a"></div>
  5. <div class="b"></div>
  6. </div>
  7. <div class="back" @click="toBack">
  8. <el-icon>
  9. <back />
  10. </el-icon>
  11. 返回
  12. </div>
  13. <div class="panel" :class="[`is-${step.value}`]">
  14. <div class="head">
  15. <p class="title">Cool Ai 极速编码</p>
  16. <p class="tag">让软件开发<span>再</span>快一点</p>
  17. <p class="desc">
  18. {{ desc.text }}
  19. </p>
  20. </div>
  21. <div class="start" v-if="step.value == 'start'">
  22. <el-button class="go btn-primary" @click="step.next">
  23. 快速开始
  24. <el-icon>
  25. <arrow-right-bold />
  26. </el-icon>
  27. </el-button>
  28. <el-button class="doc" @click="toDoc"> 文档 </el-button>
  29. </div>
  30. <div class="enter" v-if="step.value == 'enter'">
  31. <el-input
  32. :ref="setRefs('inputEntity')"
  33. v-model="form.entity"
  34. placeholder="如:收货地址、商品列表"
  35. @keydown.enter="step.next"
  36. />
  37. <el-icon class="icon is-loading" v-if="step.loading">
  38. <loading />
  39. </el-icon>
  40. <cl-svg class="icon" name="enter" v-else @click="step.next" />
  41. </div>
  42. <div
  43. class="form"
  44. :class="{
  45. show: ['form', 'coding'].includes(step.value)
  46. }"
  47. >
  48. <div class="editor">
  49. <div class="topbar">
  50. <div class="dots">
  51. <span></span>
  52. <span></span>
  53. <span></span>
  54. </div>
  55. </div>
  56. <div class="content">
  57. <div class="row">
  58. <div class="label">
  59. 实体名称
  60. <el-tooltip
  61. placement="top"
  62. content="指某类事物的集合名称,如:收货地址、商品列表"
  63. >
  64. <el-icon>
  65. <question-filled />
  66. </el-icon>
  67. </el-tooltip>
  68. </div>
  69. <el-input v-model="form.entity" maxlength="20" placeholder="请输入" />
  70. </div>
  71. <div class="row module">
  72. <div class="label">
  73. 模块
  74. <el-tooltip
  75. placement="top"
  76. content="前、后端模块的标识,如:user、goods、demo"
  77. >
  78. <el-icon>
  79. <question-filled />
  80. </el-icon>
  81. </el-tooltip>
  82. </div>
  83. <el-input v-model="form.module" maxlength="20" placeholder="请输入" />
  84. <el-popover
  85. :ref="setRefs('modulePopover')"
  86. :teleported="false"
  87. :popper-style="{
  88. padding: '5px',
  89. borderRadius: '6px',
  90. zIndex: 99
  91. }"
  92. placement="left"
  93. >
  94. <template #reference>
  95. <cl-svg class="add" name="arrow-down" />
  96. </template>
  97. <div class="module-list">
  98. <div
  99. class="item"
  100. v-for="(item, index) in module.dirs"
  101. :key="index"
  102. @click="
  103. () => {
  104. form.module = item;
  105. refs.modulePopover?.hide();
  106. }
  107. "
  108. >
  109. {{ item }}
  110. </div>
  111. </div>
  112. </el-popover>
  113. </div>
  114. <div class="row">
  115. <div class="label">
  116. 字段
  117. <el-tooltip
  118. placement="top"
  119. content="实体数据的字段名称,如:ID、姓名、手机号"
  120. >
  121. <el-icon>
  122. <question-filled />
  123. </el-icon>
  124. </el-tooltip>
  125. </div>
  126. <el-input v-model="form.column" maxlength="200" placeholder="请输入" />
  127. </div>
  128. <div class="row">
  129. <div class="label">
  130. 其他你想做的事
  131. <el-tooltip
  132. placement="top"
  133. content="功能的扩展,如:分页查询时姓名、手机号字段设置成可模糊搜索"
  134. >
  135. <el-icon>
  136. <question-filled />
  137. </el-icon>
  138. </el-tooltip>
  139. </div>
  140. <el-input v-model="form.other" maxlength="200" placeholder="请输入" />
  141. </div>
  142. </div>
  143. </div>
  144. <div class="btns">
  145. <el-button class="btn-primary" @click="code.create()">
  146. 生成代码
  147. <cl-svg name="code" />
  148. </el-button>
  149. </div>
  150. <div class="tips">如遇见 “代码缺失”、“请求超时”,请尝试「刷新」吧</div>
  151. </div>
  152. <div class="coding" v-if="step.value == 'coding'">
  153. <div class="editor">
  154. <div class="topbar">
  155. <div class="dots">
  156. <span
  157. @click="
  158. () => {
  159. step.prev();
  160. }
  161. "
  162. ></span>
  163. <span></span>
  164. <span></span>
  165. </div>
  166. </div>
  167. <div class="content">
  168. <div class="tabs">
  169. <div
  170. class="item"
  171. v-for="(item, index) in code.list"
  172. :key="index"
  173. :class="{
  174. active: code.active == item.value
  175. }"
  176. @click="
  177. () => {
  178. code.active = item.value;
  179. }
  180. "
  181. >
  182. {{ item.label }}
  183. </div>
  184. <div class="op" v-if="!isEmpty(code.list) && !code.loading">
  185. <el-tooltip content="重新生成" v-if="code.active == 'vue'">
  186. <el-icon @click="code.refresh()">
  187. <refresh />
  188. </el-icon>
  189. </el-tooltip>
  190. <el-tooltip content="复制代码">
  191. <el-icon @click="code.copy()">
  192. <document-copy />
  193. </el-icon>
  194. </el-tooltip>
  195. <el-tooltip content="创建文件">
  196. <el-icon @click="createFile">
  197. <download />
  198. </el-icon>
  199. </el-tooltip>
  200. </div>
  201. </div>
  202. <div class="code">
  203. <cl-editor-monaco
  204. :ref="setRefs('editor')"
  205. v-model="activeCode.content"
  206. height="100%"
  207. :border="false"
  208. :options="{
  209. theme: 'ai-code--dark'
  210. }"
  211. :key="activeCode.value"
  212. :language="activeCode.value == 'vue' ? 'html' : 'typescript'"
  213. v-if="activeCode"
  214. />
  215. </div>
  216. <div class="console">
  217. <el-scrollbar :ref="setRefs('console.scrollbar')">
  218. <div class="item" v-for="(item, index) in code.logs" :key="index">
  219. <span class="date"> {{ item.date }} </span>
  220. <span class="text">
  221. {{ item.text }}
  222. </span>
  223. <el-icon
  224. class="is-loading"
  225. v-if="code.loading ? index == code.logs.length - 1 : false"
  226. >
  227. <loading />
  228. </el-icon>
  229. </div>
  230. </el-scrollbar>
  231. </div>
  232. </div>
  233. </div>
  234. </div>
  235. </div>
  236. <!-- 创建菜单 -->
  237. <cl-form ref="Form" />
  238. </div>
  239. </template>
  240. <script lang="tsx" setup name="helper-ai-code">
  241. import { onMounted, reactive, computed } from "vue";
  242. import { useCool, module } from "/@/cool";
  243. import {
  244. Download,
  245. Back,
  246. ArrowRightBold,
  247. Loading,
  248. DocumentCopy,
  249. QuestionFilled,
  250. Refresh
  251. } from "@element-plus/icons-vue";
  252. import { ElMessage, ElMessageBox } from "element-plus";
  253. import { assign, isEmpty } from "lodash-es";
  254. import { useMenu, useAi } from "../hooks";
  255. import { config, isDev } from "/@/config";
  256. import { useForm } from "@cool-vue/crud";
  257. import * as monaco from "monaco-editor";
  258. import { sleep, storage } from "/@/cool/utils";
  259. import dayjs from "dayjs";
  260. import { nextTick } from "vue";
  261. import type { CodeItem } from "../types";
  262. import { useClipboard } from "@vueuse/core";
  263. const { service, refs, setRefs, router } = useCool();
  264. const menu = useMenu();
  265. const ai = useAi();
  266. const Form = useForm();
  267. const { copy } = useClipboard();
  268. // 编辑器样式
  269. monaco.editor.defineTheme("ai-code--dark", {
  270. base: "vs-dark",
  271. inherit: true,
  272. rules: [],
  273. colors: {
  274. "editor.background": "#0f151e",
  275. "editor.inactiveSelectionBackground": "#0f151e"
  276. }
  277. });
  278. // 表单
  279. const form = reactive({
  280. entity: "",
  281. module: "",
  282. other: "",
  283. column: ""
  284. });
  285. // 执行步骤
  286. const step = reactive({
  287. loading: false,
  288. value: "start",
  289. list: ["start", "enter", "form", "coding"],
  290. async next() {
  291. if (step.loading) {
  292. return false;
  293. }
  294. step.loading = true;
  295. let active = step.value;
  296. const i = step.list.indexOf(active);
  297. if (i < step.list.length - 1) {
  298. active = step.list[i + 1];
  299. }
  300. switch (active) {
  301. case "enter":
  302. setTimeout(() => {
  303. refs.inputEntity.focus();
  304. }, 300);
  305. break;
  306. case "form":
  307. if (!form.entity) {
  308. step.loading = false;
  309. return false;
  310. }
  311. await code.getColumns();
  312. break;
  313. }
  314. step.loading = false;
  315. step.value = active;
  316. // 切换文案
  317. desc.change();
  318. },
  319. prev() {
  320. const i = step.list.indexOf(step.value);
  321. if (i > 0) {
  322. step.value = step.list[i - 1];
  323. }
  324. }
  325. });
  326. // 代码
  327. const code = reactive({
  328. active: "node-entity",
  329. // 代码列表
  330. list: (storage.get("ai-code.list") || []) as CodeItem[],
  331. // 其他数据
  332. data: (storage.get("ai-code.data") || {}) as any,
  333. // 日志
  334. logs: [] as any[],
  335. // 生成中
  336. loading: false,
  337. // 获取字段
  338. async getColumns() {
  339. return ai
  340. .invokeFlow("comm-column", {
  341. name: form.entity,
  342. modules: module.dirs
  343. })
  344. .then((res) => {
  345. form.column = res.columns;
  346. form.entity = res.module;
  347. });
  348. },
  349. // 清空
  350. clear() {
  351. code.list = [];
  352. code.logs = [];
  353. },
  354. // 提示
  355. tips(val?: string) {
  356. code.logs.push({
  357. date: dayjs().format("HH:mm:ss"),
  358. text: val
  359. });
  360. // 日志滚动
  361. nextTick(() => {
  362. refs["console.scrollbar"]?.wrapRef?.scrollTo({
  363. top: Math.random() + 10000,
  364. behavior: "smooth"
  365. });
  366. });
  367. },
  368. // 生成代码
  369. async create() {
  370. if (!form.entity) {
  371. return ElMessage.warning("请填写实体名称");
  372. }
  373. if (!form.module) {
  374. return ElMessage.warning("请填写模块");
  375. }
  376. if (!form.column) {
  377. return ElMessage.warning("请填写字段");
  378. }
  379. code.loading = true;
  380. // 清空
  381. code.clear();
  382. // 下一步
  383. step.next();
  384. code.tips("AI 开始编码");
  385. await sleep(300);
  386. code.tips("Entity 代码生成中");
  387. // entity 代码
  388. const entity = await code.setContent("Entity 实体", "node-entity");
  389. code.tips("Entity 生成成功,开始解析");
  390. // entity 关键数据
  391. const entityData = await ai.invokeFlow("comm-parse-entity", {
  392. entity
  393. });
  394. code.tips(`Entity 解析成功,${JSON.stringify(entityData)}`);
  395. code.tips("Service 代码生成中");
  396. // service 代码
  397. const service = await code.setContent("Service 服务层", "node-service", {
  398. ...entityData,
  399. entity
  400. });
  401. code.tips("Service 生成成功,开始解析");
  402. // service 关键数据
  403. const serviceData = await ai.invokeFlow("comm-parse-service", {
  404. service
  405. });
  406. code.tips(`Service 解析成功,${JSON.stringify(serviceData)}`);
  407. code.tips("Controller 代码生成中");
  408. // controller 代码
  409. await code.setContent("Controller 控制器", "node-controller", {
  410. ...serviceData,
  411. ...entityData,
  412. service,
  413. entity
  414. });
  415. code.tips("Controller 生成成功");
  416. await code.createVue();
  417. code.tips("编码完成");
  418. code.loading = false;
  419. ElMessageBox.confirm("编码完成,是否创建文件?", "提示", {
  420. type: "success",
  421. confirmButtonText: "开始创建",
  422. cancelButtonText: "稍后再看"
  423. })
  424. .then(() => {
  425. createFile();
  426. })
  427. .catch(() => null);
  428. },
  429. // 创建vue
  430. async createVue() {
  431. const item = code.add("Vue 页面", "vue");
  432. item.content = "";
  433. code.data = {
  434. router: "",
  435. prefix: "",
  436. path: "",
  437. fileName: "",
  438. className: "",
  439. columns: [],
  440. api: [
  441. {
  442. path: "/add",
  443. summary: "新增"
  444. },
  445. {
  446. path: "/info",
  447. summary: "单个信息"
  448. },
  449. {
  450. path: "/update",
  451. summary: "修改"
  452. },
  453. {
  454. path: "/delete",
  455. summary: "删除"
  456. },
  457. {
  458. path: "/page",
  459. summary: "分页查询"
  460. },
  461. {
  462. path: "/list",
  463. summary: "列表查询"
  464. }
  465. ],
  466. ...form,
  467. name: form.entity
  468. };
  469. code.tips("Vue 代码生成中");
  470. // 解析
  471. await service.base.sys.menu
  472. .parse({
  473. module: form.module,
  474. entity: code.getContent("node-entity")
  475. })
  476. .then((res) => {
  477. res.router = res.path.replace("/admin", "");
  478. res.prefix = res.path;
  479. assign(code.data, res);
  480. });
  481. code.tips("AI 分析字段中");
  482. // ai分析
  483. await ai.matchType({ columns: code.data.columns, name: form.entity });
  484. // 生成内容
  485. item.content = menu.createVue(code.data);
  486. await sleep(300);
  487. // 格式化
  488. refs.editor.formatCode();
  489. code.tips("Vue 生成成功");
  490. },
  491. // 添加 tab
  492. add(label: string, flow: string) {
  493. let item = code.list.find((e) => e.value == flow);
  494. if (!item) {
  495. item = reactive<CodeItem>({
  496. label,
  497. value: flow,
  498. content: "",
  499. _content: ""
  500. });
  501. code.list.push(item);
  502. }
  503. code.active = flow;
  504. return item;
  505. },
  506. // 获取数据
  507. get(value: string) {
  508. return code.list.find((e) => e.value == value)!;
  509. },
  510. // 获取内容
  511. getContent(value: string) {
  512. return code.list.find((e) => e.value == value)?.content;
  513. },
  514. // 设置内容
  515. async setContent(label: string, flow: string, data?: any) {
  516. return new Promise((resolve) => {
  517. const item = code.add(label, flow);
  518. // 是否结束
  519. let isEnd = false;
  520. // 所有内容
  521. let content = "";
  522. ai.invokeFlow(flow, { ...form, ...data }, (res) => {
  523. isEnd = res.isEnd;
  524. if (!res.isEnd) {
  525. content += res.content;
  526. if (content.indexOf("```typescript\n") == 0) {
  527. item._content = content
  528. .replace(/^```typescript\n/g, "")
  529. .replace(/```$/, "");
  530. }
  531. }
  532. });
  533. const timer = setInterval(() => {
  534. if (step.value != "coding") {
  535. clearInterval(timer);
  536. return;
  537. }
  538. const v = item._content[item.content.length] || "";
  539. if (isEnd) {
  540. if (!v) {
  541. clearInterval(timer);
  542. resolve(item.content);
  543. return false;
  544. }
  545. }
  546. item.content += v;
  547. // 滚动到底
  548. if (flow == code.active) {
  549. refs.editor?.revealLine(99999);
  550. }
  551. }, 10);
  552. });
  553. },
  554. // 复制
  555. copy() {
  556. copy(code.getContent(code.active)!);
  557. code.save();
  558. ElMessage.success("复制成功");
  559. },
  560. // 重新生成
  561. async refresh() {
  562. code.loading = true;
  563. await code.createVue();
  564. code.loading = false;
  565. },
  566. // 保存
  567. save() {
  568. storage.set("ai-code.list", code.list);
  569. storage.set("ai-code.data", code.data);
  570. }
  571. });
  572. const activeCode = computed(() => {
  573. return code.list.find((e) => e.value == code.active);
  574. });
  575. // 滚动文案
  576. const desc = reactive({
  577. list: [] as string[],
  578. text: "",
  579. change() {
  580. switch (step.value) {
  581. case "enter":
  582. desc.list = ["请简要描述您的功能,AI帮你写代码"];
  583. break;
  584. case "form":
  585. desc.list = ["准备就绪,配置预设参数"];
  586. break;
  587. default:
  588. desc.list = [
  589. "为开发者生成优质编程代码",
  590. "只需少量的口语提示就能完成特定的功能,大大节省开发时间"
  591. ];
  592. }
  593. desc.start();
  594. },
  595. t1: null as any,
  596. t2: null as any,
  597. start() {
  598. desc.stop();
  599. function next(n: number) {
  600. const val = desc.list[n];
  601. if (val) {
  602. function next2(n2: number) {
  603. const v = val[n2];
  604. if (v) {
  605. desc.t2 = setTimeout(() => {
  606. desc.text += v;
  607. next2(n2 + 1);
  608. }, 60);
  609. } else {
  610. desc.t2 = setTimeout(() => {
  611. if (desc.list.length > 1) {
  612. desc.t1 = setInterval(() => {
  613. desc.text = desc.text.slice(0, -1);
  614. if (!desc.text) {
  615. clearInterval(desc.t1);
  616. next(n + 1);
  617. }
  618. }, 50);
  619. }
  620. }, 1500);
  621. }
  622. }
  623. next2(0);
  624. } else {
  625. next(0);
  626. }
  627. }
  628. if (!isEmpty(desc.list)) {
  629. next(0);
  630. }
  631. },
  632. stop() {
  633. if (desc.t1) {
  634. clearInterval(desc.t1);
  635. }
  636. if (desc.t2) {
  637. clearTimeout(desc.t2);
  638. }
  639. desc.text = "";
  640. },
  641. init() {
  642. desc.change();
  643. }
  644. });
  645. // 创建文件
  646. function createFile() {
  647. if (!isDev) {
  648. return ElMessage.error("只有在开发环境下才有效");
  649. }
  650. Form.value?.open({
  651. title: "配置菜单",
  652. width: "800px",
  653. items: [
  654. {
  655. prop: "parentId",
  656. label: "上级节点",
  657. component: {
  658. name: "cl-menu-select",
  659. props: {
  660. type: 1
  661. }
  662. }
  663. },
  664. {
  665. prop: "keepAlive",
  666. value: true,
  667. label: "路由缓存",
  668. component: {
  669. name: "el-radio-group",
  670. options: [
  671. {
  672. label: "开启",
  673. value: true
  674. },
  675. {
  676. label: "关闭",
  677. value: false
  678. }
  679. ]
  680. }
  681. },
  682. {
  683. prop: "icon",
  684. label: "菜单图标",
  685. component: {
  686. name: "cl-menu-icon"
  687. }
  688. },
  689. {
  690. prop: "orderNum",
  691. label: "排序号",
  692. component: {
  693. name: "el-input-number",
  694. props: {
  695. placeholder: "请填写排序号",
  696. min: 0,
  697. max: 99,
  698. "controls-position": "right"
  699. }
  700. }
  701. }
  702. ],
  703. op: {
  704. saveButtonText: "开始创建"
  705. },
  706. on: {
  707. submit(data, { close }) {
  708. code.tips("创建 Vue 文件中,过程可能会发生页面及服务重启");
  709. close();
  710. // 添加菜单、权限
  711. menu.create({
  712. code: code.getContent("vue"),
  713. ...code.data,
  714. ...data
  715. })
  716. .then((create) => {
  717. // 创建后端文件
  718. service.base.sys.menu.create({
  719. ...form,
  720. ...code.data,
  721. controller: code.getContent("node-controller"),
  722. entity: code.getContent("node-entity"),
  723. service: code.getContent("node-service")
  724. });
  725. // 每3s检测服务状态
  726. const timer = setInterval(() => {
  727. code.tips("检测后端服务是否启动");
  728. service
  729. .request({
  730. url: "/"
  731. })
  732. .then(() => {
  733. code.tips("文件创建成功");
  734. ElMessage.success("文件创建成功");
  735. clearInterval(timer);
  736. create();
  737. });
  738. }, 3000);
  739. })
  740. .catch(() => null);
  741. }
  742. }
  743. });
  744. }
  745. // 文档
  746. function toDoc() {
  747. window.open("https://cool-js.com/");
  748. }
  749. // 返回
  750. function toBack() {
  751. ElMessageBox.confirm(`确定要返回 ${config.app.name} 吗?`, "提示", {
  752. type: "warning"
  753. })
  754. .then(() => {
  755. router.back();
  756. })
  757. .catch(() => {});
  758. }
  759. onMounted(() => {
  760. desc.init();
  761. });
  762. </script>
  763. <style lang="scss" scoped>
  764. $color: #41d1ff;
  765. .ai-code {
  766. display: flex;
  767. flex-direction: column;
  768. justify-content: center;
  769. align-items: center;
  770. position: relative;
  771. height: 100vh;
  772. overflow: hidden;
  773. .bg {
  774. position: absolute;
  775. left: 0;
  776. top: 0;
  777. height: 100%;
  778. width: 100%;
  779. background-color: #090c13;
  780. display: flex;
  781. justify-content: center;
  782. .a {
  783. background-color: $color;
  784. transform: rotate(20deg);
  785. right: -10px;
  786. }
  787. .b {
  788. background-color: #4165d7;
  789. transform: rotate(-20deg);
  790. right: 10px;
  791. }
  792. .a,
  793. .b {
  794. height: 300px;
  795. width: 420px;
  796. position: relative;
  797. opacity: 0.4;
  798. border-radius: 100%;
  799. filter: blur(60px);
  800. top: 30vh;
  801. animation: fb 5s ease-in-out infinite;
  802. }
  803. @keyframes fb {
  804. 0% {
  805. filter: blur(60px);
  806. }
  807. 40% {
  808. filter: blur(150px);
  809. }
  810. 80% {
  811. filter: blur(60px);
  812. }
  813. 100% {
  814. filter: blur(60px);
  815. }
  816. }
  817. }
  818. .back {
  819. display: flex;
  820. align-items: center;
  821. justify-content: center;
  822. position: fixed;
  823. left: 20px;
  824. top: 20px;
  825. color: #fff;
  826. border: 1px solid rgba(255, 255, 255, 0.8);
  827. border-radius: 30px;
  828. padding: 6px 13px 6px 10px;
  829. cursor: pointer;
  830. transition: all 0.2s;
  831. font-size: 12px;
  832. z-index: 9;
  833. .el-icon {
  834. font-size: 16px;
  835. margin-right: 8px;
  836. }
  837. &:hover {
  838. background-color: rgba(255, 255, 255, 0.1);
  839. }
  840. }
  841. .panel {
  842. display: flex;
  843. flex-direction: column;
  844. justify-content: center;
  845. align-items: center;
  846. position: relative;
  847. height: 100%;
  848. width: 1040px;
  849. max-width: 100%;
  850. .editor {
  851. background-color: #080e14;
  852. width: 100%;
  853. .topbar {
  854. display: flex;
  855. align-items: center;
  856. height: 36px;
  857. padding: 0 12px;
  858. .dots {
  859. display: flex;
  860. span {
  861. display: inline-block;
  862. height: 12px;
  863. width: 12px;
  864. border-radius: 12px;
  865. background-color: #2f3447;
  866. margin-right: 8px;
  867. }
  868. }
  869. }
  870. .content {
  871. background-color: #0f151e;
  872. }
  873. }
  874. .btn-primary {
  875. border: 0;
  876. background-size: 300% 100%;
  877. background-image: linear-gradient(-60deg, $color, rgba($color, 0.5), $color);
  878. background-position: 100% 0px;
  879. box-shadow: 0 0 10px 1px rgba(255, 255, 255, 0.2);
  880. border-radius: 8px;
  881. letter-spacing: 1px;
  882. color: #111;
  883. transition: all 0.3s ease;
  884. .el-icon {
  885. transition: transform 0.1s;
  886. }
  887. &:hover {
  888. background-position: 0% 0px;
  889. .el-icon {
  890. transform: translateX(5px);
  891. }
  892. }
  893. }
  894. .head {
  895. padding: 50px 0;
  896. text-align: center;
  897. color: #fff;
  898. line-height: 1;
  899. letter-spacing: 2px;
  900. user-select: none;
  901. transition: all 0.2s ease 0.1s;
  902. .title {
  903. display: inline-block;
  904. font-size: 40px;
  905. background-clip: text;
  906. font-weight: bold;
  907. text-shadow: 0 5px 10px #333;
  908. transition: all 0.3s;
  909. transition-delay: 0.2s;
  910. }
  911. .tag {
  912. margin-top: 30px;
  913. font-size: 18px;
  914. color: #eee;
  915. span {
  916. color: $color;
  917. padding: 0 2px;
  918. }
  919. }
  920. .desc {
  921. display: flex;
  922. align-items: center;
  923. justify-content: center;
  924. height: 35px;
  925. padding: 0 1px;
  926. color: #fff;
  927. font-size: 22px;
  928. margin-top: 50px;
  929. &::after {
  930. content: "";
  931. display: inline-block;
  932. margin-left: 4px;
  933. height: 22px;
  934. width: 3px;
  935. background-color: #fff;
  936. border-radius: 3px;
  937. animation: shan 1s ease infinite;
  938. }
  939. @keyframes shan {
  940. 0% {
  941. opacity: 0;
  942. }
  943. 50% {
  944. opacity: 1;
  945. }
  946. 100% {
  947. opacity: 0;
  948. }
  949. }
  950. }
  951. }
  952. .start {
  953. height: 50px;
  954. text-align: center;
  955. margin: 0 auto;
  956. flex-shrink: 0;
  957. .el-button {
  958. height: 40px;
  959. background-color: #fff;
  960. border-radius: 8px;
  961. }
  962. .go {
  963. width: 140px;
  964. .el-icon {
  965. margin-left: 5px;
  966. color: #444;
  967. }
  968. }
  969. .doc {
  970. background-color: transparent;
  971. width: 100px;
  972. color: #fff;
  973. border-width: 2px;
  974. border-color: rgba(255, 255, 255, 0.7);
  975. }
  976. }
  977. .enter {
  978. display: flex;
  979. align-items: center;
  980. margin: 0 auto;
  981. position: relative;
  982. animation: enter 0.3s forwards;
  983. width: 10px;
  984. :deep(.el-input__wrapper) {
  985. background-color: rgba(0, 0, 0, 0.3);
  986. padding: 10px 20px;
  987. border-radius: 12px;
  988. box-shadow: 0 0 10px 1px #4165d719;
  989. .el-input__inner {
  990. color: #fff;
  991. font-size: 16px;
  992. text-align: center;
  993. letter-spacing: 2px;
  994. }
  995. }
  996. .icon {
  997. position: absolute;
  998. right: 18px;
  999. color: #ccc;
  1000. font-size: 18px;
  1001. cursor: pointer;
  1002. &:hover {
  1003. color: #fff;
  1004. }
  1005. }
  1006. }
  1007. @keyframes enter {
  1008. from {
  1009. width: 10px;
  1010. }
  1011. to {
  1012. width: 320px;
  1013. }
  1014. }
  1015. .form {
  1016. transform: translateY(50vh);
  1017. width: calc(100% - 40px);
  1018. transition: all 0.3s ease;
  1019. margin: 0 auto;
  1020. .editor {
  1021. border-radius: 8px;
  1022. .content {
  1023. color: #fff;
  1024. box-sizing: border-box;
  1025. border-radius: 0 0 8px 8px;
  1026. padding: 5px 0 10px 0;
  1027. .row {
  1028. font-size: 12px;
  1029. margin-bottom: 10px;
  1030. &:last-child {
  1031. margin-bottom: 0;
  1032. }
  1033. .label {
  1034. display: flex;
  1035. align-items: center;
  1036. padding: 5px 15px;
  1037. font-size: 12px;
  1038. margin-bottom: 5px;
  1039. color: #999;
  1040. .el-icon {
  1041. margin-left: 4px;
  1042. cursor: pointer;
  1043. }
  1044. }
  1045. :deep(.el-input__wrapper) {
  1046. background-color: #2f344722;
  1047. box-shadow: none;
  1048. padding: 0 15px;
  1049. .el-input__inner {
  1050. color: #fff;
  1051. }
  1052. .el-icon {
  1053. margin-left: 2px;
  1054. }
  1055. }
  1056. &.module {
  1057. position: relative;
  1058. :deep(.el-input__wrapper) {
  1059. padding-left: 35px;
  1060. }
  1061. .add {
  1062. cursor: pointer;
  1063. margin-right: 8px;
  1064. position: absolute;
  1065. left: 15px;
  1066. top: 40px;
  1067. }
  1068. }
  1069. }
  1070. }
  1071. }
  1072. .btns {
  1073. display: flex;
  1074. justify-content: center;
  1075. .el-button {
  1076. height: 50px;
  1077. width: 200px;
  1078. font-size: 16px;
  1079. }
  1080. .cl-svg {
  1081. font-size: 18px;
  1082. margin-left: 5px;
  1083. color: #333;
  1084. }
  1085. }
  1086. .tips {
  1087. color: #eee;
  1088. text-align: center;
  1089. font-size: 14px;
  1090. user-select: none;
  1091. margin-top: 30px;
  1092. }
  1093. .module-list {
  1094. .item {
  1095. border-radius: 6px;
  1096. display: flex;
  1097. align-items: center;
  1098. height: 30px;
  1099. padding: 0 10px;
  1100. cursor: pointer;
  1101. border-radius: 6px;
  1102. font-size: 12px;
  1103. &:hover {
  1104. background-color: var(--el-fill-color-light);
  1105. }
  1106. }
  1107. }
  1108. &.show {
  1109. transform: translateY(0);
  1110. .btns {
  1111. margin-top: 60px;
  1112. }
  1113. }
  1114. }
  1115. .coding {
  1116. position: fixed;
  1117. bottom: 0;
  1118. left: 0;
  1119. height: 100vh;
  1120. width: 100%;
  1121. animation: coding 0.3s forwards;
  1122. box-sizing: border-box;
  1123. opacity: 0;
  1124. z-index: 10;
  1125. .editor {
  1126. height: 100%;
  1127. border-radius: 10px 10px 0 0;
  1128. }
  1129. .topbar {
  1130. .dots {
  1131. span {
  1132. cursor: pointer;
  1133. &:first-child {
  1134. &:hover {
  1135. background-color: var(--el-color-danger);
  1136. }
  1137. }
  1138. }
  1139. }
  1140. }
  1141. .content {
  1142. height: calc(100% - 36px);
  1143. background-color: #080e14;
  1144. .tabs {
  1145. display: flex;
  1146. height: 40px;
  1147. .item {
  1148. display: flex;
  1149. align-items: center;
  1150. justify-content: center;
  1151. padding: 0 15px;
  1152. font-size: 12px;
  1153. cursor: pointer;
  1154. color: var(--el-color-info);
  1155. &.active {
  1156. background-color: #0f151e;
  1157. color: #fff;
  1158. }
  1159. &:hover {
  1160. color: #eee;
  1161. }
  1162. }
  1163. .op {
  1164. display: flex;
  1165. align-items: center;
  1166. margin-left: auto;
  1167. margin-right: 5px;
  1168. .el-icon {
  1169. height: 30px;
  1170. width: 30px;
  1171. color: #fff;
  1172. font-size: 15px;
  1173. cursor: pointer;
  1174. border-radius: 5px;
  1175. &:hover {
  1176. background-color: #0f151e;
  1177. }
  1178. }
  1179. }
  1180. }
  1181. .code {
  1182. height: calc(100% - 190px);
  1183. }
  1184. .console {
  1185. height: 150px;
  1186. padding: 5px 0;
  1187. box-sizing: border-box;
  1188. border-top: 1px solid #2f3447;
  1189. .item {
  1190. font-size: 12px;
  1191. padding: 5px 10px;
  1192. color: #fff;
  1193. .date {
  1194. margin-right: 5px;
  1195. color: #ccc;
  1196. }
  1197. .el-icon {
  1198. margin: 0 5px;
  1199. font-size: 14px;
  1200. position: relative;
  1201. top: 3px;
  1202. }
  1203. }
  1204. }
  1205. }
  1206. }
  1207. @keyframes coding {
  1208. from {
  1209. opacity: 0;
  1210. transform: translateY(10vh);
  1211. }
  1212. to {
  1213. opacity: 1;
  1214. transform: translateY(0);
  1215. }
  1216. }
  1217. }
  1218. }
  1219. </style>