Sider.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <!--
  2. - Copyright (c) 2024 LangChat. TyCoding All Rights Reserved.
  3. -
  4. - Licensed under the GNU Affero General Public License, Version 3 (the "License");
  5. - you may not use this file except in compliance with the License.
  6. - You may obtain a copy of the License at
  7. -
  8. - https://www.gnu.org/licenses/agpl-3.0.html
  9. -
  10. - Unless required by applicable law or agreed to in writing, software
  11. - distributed under the License is distributed on an "AS IS" BASIS,
  12. - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. - See the License for the specific language governing permissions and
  14. - limitations under the License.
  15. -->
  16. <script lang="ts" setup>
  17. import { computed, ref, watch } from 'vue';
  18. import { SvgIcon } from '@/components/common';
  19. import { t } from '@/locales';
  20. import ModelProvider from '@/views/modules/common/ModelProvider.vue';
  21. import { useBasicLayout } from '@/hooks/useBasicLayout';
  22. const { isMobile } = useBasicLayout();
  23. const props = defineProps<{
  24. loading: boolean;
  25. genText: string;
  26. }>();
  27. const loading = computed(() => {
  28. return props.loading;
  29. });
  30. const emit = defineEmits(['generate', 'render']);
  31. const text = ref('');
  32. const gen = ref('');
  33. watch(
  34. () => props.genText,
  35. (val) => {
  36. gen.value = val;
  37. }
  38. );
  39. function onReRender() {
  40. emit('render', gen.value);
  41. }
  42. function onCase() {
  43. text.value = `番茄炒蛋怎么做`;
  44. gen.value = `
  45. # 番茄炒蛋的制作流程
  46. ## 材料准备
  47. - 购买新鲜的番茄和鸡蛋
  48. - 准备调味料,如盐,糖,酱油等
  49. ## 制作步骤
  50. ### 步骤1:准备食材
  51. - 清洗番茄,切成块状
  52. - 破开鸡蛋,搅拌均匀
  53. ### 步骤2:炒制
  54. - 热锅凉油,倒入鸡蛋液翻炒至熟
  55. - 将炒好的鸡蛋盛出备用
  56. - 锅里重新加油,放入番茄翻炒至汁液出来
  57. ### 步骤3:调味
  58. - 倒入炒好的鸡蛋,加入适量的盐,糖,酱油等调料翻炒均匀
  59. ### 步骤4:出锅
  60. - 炒至食材完全融合,出锅即可
  61. ## 注意事项
  62. - 注意控制火候,避免炒焦
  63. - 根据个人口味调整调料比例
  64. `;
  65. emit('render', gen.value);
  66. }
  67. function onGenerate() {
  68. emit('generate', text.value);
  69. }
  70. </script>
  71. <template>
  72. <div :class="isMobile ? '' : 'w-[65%] border-r'" class="p-4 pt-2">
  73. <div class="py-2 flex items-center justify-between gap-1">
  74. <div class="text-nowrap">内容描述</div>
  75. <ModelProvider />
  76. </div>
  77. <n-input
  78. v-model:value="text"
  79. :disabled="loading"
  80. :placeholder="t('mindmap.inputTips')"
  81. :rows="isMobile ? 2 : 6"
  82. type="textarea"
  83. />
  84. <div class="mt-2 mb-2">
  85. <n-button :loading="loading" block secondary type="success" @click="onGenerate">
  86. <template #icon>
  87. <SvgIcon class="text-lg" icon="ion:sparkles-outline" />
  88. </template>
  89. {{ t('mindmap.confirm') }}
  90. </n-button>
  91. </div>
  92. <div class="mt-6">
  93. <div class="flex flex-wrap justify-between items-center mb-2">
  94. <div class="flex items-center gap-1">
  95. <span>{{ t('mindmap.output') }}</span>
  96. <n-button text type="success" @click="onCase">{{ t('mindmap.example') }}</n-button>
  97. </div>
  98. <n-button secondary size="tiny" type="success" @click="onReRender">重新渲染</n-button>
  99. </div>
  100. </div>
  101. <n-input
  102. v-model:value="gen"
  103. :placeholder="t('mindmap.outputTips')"
  104. :rows="isMobile ? 6 : 16"
  105. type="textarea"
  106. />
  107. </div>
  108. </template>
  109. <style lang="less" scoped></style>