AIPainting.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <template>
  2. <!-- 智能绘画 -->
  3. <div class="home-container">
  4. <!-- 左侧折叠面板 -->
  5. <div class="left-group">
  6. <div class="title-box">
  7. <div class="box-icon" @click="goBack">
  8. <el-icon class="left-icon"><ArrowLeftBold /></el-icon>
  9. 智能绘画
  10. </div>
  11. </div>
  12. </div>
  13. <!-- 右侧AI问答 -->
  14. <div class="number-people">
  15. <div class="content-box">
  16. <!-- AI对话框 -->
  17. <div class="chat-dialog">
  18. <!-- 对话消息列表 -->
  19. <div class="message-list">
  20. <!-- 用户消息 -->
  21. <div class="user-message">生成图片</div>
  22. <!-- AI生成图片对话框 -->
  23. <div class="ai-message">
  24. 接下来我将生成四张会飞的猪的图片。画面风格是写实风,主体是一只身体肥硕、粉色皮肤、小短腿的猪,它长着两只大耳朵和一条卷曲的尾巴,正扇动着一对白色的翅膀在空中飞行。<br />
  25. <div class="image-list">
  26. <el-image
  27. v-for="(image, index) in srcList"
  28. :key="index"
  29. style=" width: fit-content; height: 150px; margin: 10px;"
  30. :src="image"
  31. :preview-src-list="srcList"
  32. fit="cover"
  33. show-progress
  34. >
  35. <template
  36. #toolbar="{ actions, prev, next, reset, activeIndex, setActiveItem }"
  37. >
  38. <el-icon @click="prev"><Back /></el-icon>
  39. <el-icon @click="next"><Right /></el-icon>
  40. <el-icon @click="setActiveItem(srcList.length - 1)">
  41. <DArrowRight />
  42. </el-icon>
  43. <el-icon @click="actions('zoomOut')"><ZoomOut /></el-icon>
  44. <el-icon
  45. @click="actions('zoomIn', { enableTransition: false, zoomRate: 2 })">
  46. <ZoomIn />
  47. </el-icon>
  48. <el-icon
  49. @click="actions('clockwise', { rotateDeg: 180, enableTransition: false })">
  50. <RefreshRight />
  51. </el-icon>
  52. <el-icon @click="actions('anticlockwise')"><RefreshLeft /></el-icon>
  53. <el-icon @click="reset"><Refresh /></el-icon>
  54. <el-icon @click="download(activeIndex)"><Download /></el-icon>
  55. </template>
  56. </el-image>
  57. </div>
  58. </div>
  59. </div>
  60. <!-- 输入框和发送按钮 -->
  61. <div class="input-section">
  62. <input
  63. type="text"
  64. v-model="inputMessage"
  65. placeholder="说说你的灵感..."
  66. />
  67. <button @click="sendMessage">发送</button>
  68. </div>
  69. </div>
  70. </div>
  71. </div>
  72. </div>
  73. </template>
  74. <script setup>
  75. import { ref, onMounted } from 'vue'
  76. import { CreatePainting,CreatePaintingGetMy} from '@/api/questions.js'
  77. import { useRouter, useRoute } from 'vue-router'
  78. import {
  79. Document,
  80. Menu as IconMenu,
  81. Location,
  82. Setting,
  83. ArrowLeftBold
  84. } from '@element-plus/icons-vue'
  85. // 返回上一页
  86. const goBack = () => {
  87. router.go(-1)
  88. }
  89. const router = useRouter()
  90. const route = useRoute()
  91. // AI生成图片
  92. CreatePainting({
  93. modelId: 56,
  94. prompt:''
  95. }).then(res=>{
  96. console.log(res);
  97. })
  98. // 获取绘图记录
  99. // CreatePaintingGetMy().then(res=>{
  100. // console.log(res);
  101. // })
  102. // 消息列表和输入内容的响应式变量
  103. const messages = ref([])
  104. const inputMessage = ref('')
  105. // 发送消息函数
  106. const sendMessage = () => {
  107. if (inputMessage.value.trim()) {
  108. messages.value.push(inputMessage.value.trim())
  109. inputMessage.value = ''
  110. }
  111. }
  112. // 生成图片
  113. import { ElIcon } from 'element-plus'
  114. import {
  115. Back,
  116. DArrowRight,
  117. Download,
  118. Refresh,
  119. RefreshLeft,
  120. RefreshRight,
  121. Right,
  122. ZoomIn,
  123. ZoomOut,
  124. } from '@element-plus/icons-vue'
  125. const url =
  126. 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg'
  127. const srcList = [
  128. 'https://fuss10.elemecdn.com/a/3f/3302e58f9a181d2509f3dc0fa68b0jpeg.jpeg',
  129. 'https://fuss10.elemecdn.com/1/34/19aa98b1fcb2781c4fba33d850549jpeg.jpeg',
  130. 'https://fuss10.elemecdn.com/0/6f/e35ff375812e6b0020b6b4e8f9583jpeg.jpeg',
  131. 'https://fuss10.elemecdn.com/9/bb/e27858e973f5d7d3904835f46abbdjpeg.jpeg',
  132. 'https://fuss10.elemecdn.com/d/e6/c4d93a3805b3ce3f323f7974e6f78jpeg.jpeg',
  133. 'https://fuss10.elemecdn.com/3/28/bbf893f792f03a54408b3b7a7ebf0jpeg.jpeg',
  134. 'https://fuss10.elemecdn.com/2/11/6535bcfb26e4c79b48ddde44f4b6fjpeg.jpeg',
  135. ]
  136. </script>
  137. <style scoped lang="scss">
  138. @use 'sass:math';
  139. // 定义rpx转换函数
  140. @function rpx($px) {
  141. @return math.div($px, 750) * 100vw;
  142. }
  143. .home-container {
  144. position: fixed;
  145. top: 0;
  146. left: 0;
  147. right: 0;
  148. bottom: 0;
  149. display: flex;
  150. flex-direction: row;
  151. gap: rpx(0);
  152. }
  153. // 侧边栏
  154. .left-group {
  155. width: rpx(150);
  156. height: 100%;
  157. background-color: #ece9fd;
  158. }
  159. .left-group img {
  160. width: rpx(120);
  161. height: auto;
  162. margin-top: rpx(30);
  163. }
  164. .title-box {
  165. height: rpx(50);
  166. }
  167. .box-icon {
  168. width: 100%;
  169. height: 100%;
  170. flex: 1;
  171. display: flex; // 添加 flex 布局
  172. align-items: center; // 垂直居中
  173. color: black; // 设置图标颜色为白色
  174. padding-left: rpx(15);
  175. font-size: rpx(10); // 设置图标大小,可按需调整
  176. cursor: pointer; // 添加鼠标指针样式
  177. }
  178. .box-icon .left-icon {
  179. margin-left: rpx(10);
  180. margin-right: rpx(5); // 设置图标和文字之间的间距 ;
  181. }
  182. .number-people {
  183. flex: 1;
  184. height: 100%;
  185. display: flex;
  186. background-color: #ece9fd;
  187. }
  188. .content-box {
  189. flex: 1;
  190. margin-top: rpx(10);
  191. margin-bottom: rpx(10);
  192. margin-right: rpx(10);
  193. border-radius: rpx(15);
  194. background: rgba($color: #ffffff, $alpha: 0.5);
  195. }
  196. // 对话框
  197. .chat-dialog {
  198. display: flex;
  199. flex-direction: column;
  200. height: 100%;
  201. }
  202. .message-list {
  203. flex: 1;
  204. overflow-y: auto;
  205. padding: rpx(15);
  206. }
  207. .message-list .user-message {
  208. background-color: #ffffff;
  209. margin-left: auto; // 消息靠右显示
  210. margin-right: 0; // 重置右边距
  211. max-width: rpx(400);
  212. font-size: rpx(8);
  213. width: fit-content; // 宽度随文字内容变化
  214. border-radius: rpx(5);
  215. padding: rpx(5);
  216. text-align: left; // 文字左对齐
  217. }
  218. .message-list .ai-message {
  219. background-color: #ffdd55;
  220. margin-left: 0; // 消息靠左显示
  221. margin-right: auto; // 重置右边距
  222. margin-bottom: rpx(10);
  223. width: fit-content;
  224. max-width: rpx(400);
  225. padding: rpx(5);
  226. font-size: rpx(8);
  227. border-radius: rpx(5);
  228. text-align: left; // 文字左对齐
  229. }
  230. .input-section {
  231. display: flex;
  232. padding: rpx(10);
  233. gap: rpx(10);
  234. }
  235. .input-section input {
  236. flex: 1;
  237. padding: rpx(5);
  238. font-size: rpx(7);
  239. border: 1px solid #ccc;
  240. border-radius: rpx(5);
  241. }
  242. .input-section button {
  243. padding: rpx(5) rpx(15);
  244. background: linear-gradient(
  245. to bottom,
  246. #fee78a,
  247. #ffce1b
  248. ); /* 设置悬停、聚焦、点击状态下的背景色 */
  249. color: black;
  250. border: none;
  251. font-size: rpx(7);
  252. border-radius: rpx(5);
  253. cursor: pointer;
  254. box-shadow: 0 4px 8px rgba(202, 52, 52, 0.3);
  255. }
  256. .image-list {
  257. display: flex;
  258. flex-wrap: wrap;
  259. }
  260. </style>