AI-draw.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. <template>
  2. <view class="container" :style="{'top': viewTop + 'px', 'height': viewHeight + 'px'}">
  3. <view class="content">
  4. <scroll-view scroll-y="true" :show-scrollbar="false" :scroll-top="scroll_top" style="top: 0%;width: 80vw; height:65%;position: absolute;">
  5. <view class="scroll-view-text">
  6. <view style="margin-left: 13%; display: flex; align-items: center;justify-content: center;width: 100%; user-select: text;" v-for="(msgIndex,index) in recvMsgQueue ">
  7. <!-- ai 的消息结构体 -->
  8. <view v-if="isAItell(recvMsgQueue[index].who_msg)" style="width: 100%;height: 100%;margin-bottom: 1%;">
  9. <text style=" font-size: 10rpx;color: #B34FFF;font-size: 10rpx;margin-left: 2%;background: linear-gradient(90deg, #24BF74 10%, #FAEE07 90%);-webkit-background-clip: text;-webkit-text-fill-color: transparent;">
  10. {{ai_name}}
  11. </text>
  12. <view style="margin-bottom: 3%; margin-top: 1%;margin-left: 1%;padding: 1%; width: 70%;background: #2A2832;border-radius: 10rpx 10rpx 10rpx 10rpx;">
  13. <view @tap="handleClick()" style="width: 100%;background-color: #2A2832;color: white;" class="htmlContent" ref="htmlContent" v-html="returnText(recvMsgQueue[index].msg_text)" >
  14. </view>
  15. <image v-if="getImg(index)!=''" :src="getImg(index)"></image>
  16. <view @click="stopRecv()" v-if="recvStatus&&recvMsgQueue[index].isFinish==false" style="display: flex;width: 100%;align-items: center;justify-content: center;">
  17. <image src="../../static/closed.png" style="width: 50upx;height: 50upx;align-self: center;"></image>
  18. </view>
  19. </view>
  20. <view v-if="false" style="margin-left: 65%;">
  21. <image src="../../static/msg-opt-3.png" style="margin-left: 10upx;width: 30upx;height: 30upx;"></image>
  22. <image src="../../static/msg-opt-4.png" style="margin-left: 10upx;width: 30upx;height: 30upx;"></image>
  23. </view>
  24. <view style=" display: flex;flex-wrap: wrap;width: 40%;">
  25. <view style="width: 25%;justify-content: center;align-items: center;display: flex;margin-top: 2%;" v-for="(item,i) in recvMsgQueue[index].actions" key="key">
  26. <view @click="clickitem(recvMsgQueue[index].actions[i],recvMsgQueue[index].image_id)" style="background-color: #24BF74;display: flex;border-radius: 25px 25px 25px 25px;align-items: center;justify-content: center;width: 100%;margin: 1%;">{{recvMsgQueue[index].actions[i]}}</view>
  27. </view>
  28. </view>
  29. </view>
  30. <!-- 我发送 的消息结构体 -->
  31. <view v-if="!isAItell(recvMsgQueue[index].who_msg)" style="width: 100%;height: 100%;margin-top: 1%;">
  32. <view style=" font-size: 10rpx;color: #B34FFF;font-size: 10rpx;margin-left: 2%;">
  33. {{user_name}}
  34. </view>
  35. <view style="margin-bottom: 3%; margin-top: 1%;margin-left: 1%;padding: 1%; width: 70%;background: #2A2832;border-radius: 10rpx 10rpx 10rpx 10rpx;">
  36. <view style="width: 100%;background-color: #2A2832;color: white;" class="htmlContent" ref="htmlContent" >
  37. {{recvMsgQueue[index].msg_text}}
  38. </view>
  39. <image v-if="recvMsgQueue[index].des_img!=''" :src="recvMsgQueue[index].des_img"></image>
  40. </view>
  41. <view v-if="false" style="margin-left: 65%;">
  42. <image src="../../static/msg-opt-1.png" style="margin-left: 10upx; width: 30upx;height: 30upx;"></image>
  43. <image src="../../static/msg-opt-2.png" style="margin-left: 10upx;width: 30upx;height: 30upx;"></image>
  44. <image src="../../static/msg-opt-3.png" style="margin-left: 10upx;width: 30upx;height: 30upx;"></image>
  45. <image src="../../static/msg-opt-4.png" style="margin-left: 10upx;width: 30upx;height: 30upx;"></image>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. </scroll-view>
  51. <view style="display: flex;width: 70vw;height: 90upx;position: absolute;bottom:500upx;">
  52. <view style="display: flex;width: 90%; border-radius: 25px 25px 25px 25px;opacity: 1;border: 1px solid #32B3AA;width: 100%;" class="textarea-box">
  53. <view style="width: 90%; height: 100%; display: flex;align-items: center;justify-content: center" >
  54. <textarea v-model="inputValue" :cursor-spacing="15" class="textarea" auto-height="true"
  55. @keydown.enter="onKeydown('enter')" :disabled="disabled"
  56. @input="onKeyInput"
  57. placeholder="请输入消息内容(使用 Enter 发送)" :maxlength="-1"
  58. placeholder-class="input-placeholder"></textarea>
  59. </view>
  60. <view v-if="recvStatus==false" style="width: 10%; height: 100%; display: flex; color: aliceblue;align-items: center;justify-content: center" @click="sendMsg">
  61. <image src="../../static/img_send.png" style="width: 29.57upx;height: 37.67upx;" ></image>
  62. </view>
  63. </view>
  64. <view style=" display: flex;align-items: center;justify-content: center;width: 5%;position: relative;">
  65. <image @click="onclickdelete()" src="../../static/img_delete.png" style="width: 50upx;height: 70upx;"></image>
  66. </view>
  67. </view>
  68. </view>
  69. <view style="position: absolute;top: 10%;right: 5%;width: 200upx;display: flex;align-items: center;justify-content: center;">
  70. <view style="color: white;margin-right: 10upx;">开启慢速</view>
  71. <image @click="is_open_relax=false" v-show="is_open_relax==true" src="../../static/img-on.png" style="width: 60upx;height: 30upx;"></image>
  72. <image @click="is_open_relax=true" v-show="is_open_relax==false" src="../../static/img-off.png" style="width: 60upx;height: 30upx;"></image>
  73. </view>
  74. <view @click="is_show_import_img_view=true" style="position: absolute;top: 20%;right: 5%;width: 200upx;display: flex;align-items: center;justify-content: center;">
  75. <view style="color: white;margin-right: 10upx;">导入图片</view>
  76. <image src="../../static/import-img.png" style="width: 60upx;height: 60upx;"></image>
  77. </view>
  78. <view v-if="is_show_import_img_view==true" style=" display: flex; height: 100vh; position: absolute;top: 0;width: 500upx;background-color:#24BF74;">
  79. <view style="width: 100%;;">
  80. <view @click="onFileInput" style="display: flex;align-items: center;justify-content: center;margin-top: 5%;center;margin-bottom: 5%;">
  81. <image :src="cur_select_img" style="width: 100upx;height: 100upx;"></image>
  82. </view>
  83. <view style="display: flex;align-items: center;justify-content: center;margin-top: 5%;center;margin-bottom: 5%;">
  84. <textarea style="display: flex;align-items: center;justify-content: center;" v-model="diy_inputValue" :cursor-spacing="15" auto-height="true"
  85. @input="onKeyInput"
  86. placeholder="请输入描述" :maxlength="-1"
  87. placeholder-class="input-placeholder"></textarea>
  88. </view>
  89. <view @click="send_diy_img()" style="display: flex;align-items: center;justify-content: center;margin-top: 5%;center;margin-bottom: 5%;">
  90. <view style="display: flex;align-items: center;justify-content: center;background-color: aqua;;border-radius: 10rpx 10rpx 10rpx 10rpx;width: 50%;">发送</view>
  91. </view>
  92. <view @click="is_show_import_img_view=false" style="display: flex;align-items: center;justify-content: center;margin-top: 5%;center;margin-bottom: 5%;">
  93. <view style="display: flex;align-items: center;justify-content: center;background-color: aqua;;border-radius: 10rpx 10rpx 10rpx 10rpx;width: 50%;">关闭</view>
  94. </view>
  95. <scroll-view scroll-y="true" style="height:500upx;">
  96. <view @click="selectImg(import_list[j])" style="display: flex;align-items: center;justify-content: center;" v-for="(itemx,j) in import_list">
  97. <image style="width: 150upx;height: 150upx;margin-top: 5%;" :src="import_list[j]"></image>
  98. </view>
  99. </scroll-view>
  100. </view>
  101. </view>
  102. <view v-if="is_up_img_file" style="align-items: center;justify-content: center;display: flex; color: aliceblue; position: absolute; width: 100vw;height:100vh;background-color: black;opacity: 70%;">
  103. 正在上传
  104. </view>
  105. </view>
  106. </template>
  107. <script>
  108. import marked from '../marked/marked.min.js';
  109. import config from '../index/config.js';
  110. import hljs from "../highlight.js/lib/common.js";
  111. import interfaces from '../../utils/interfaces.js'
  112. import "../highlight.js/styles/atom-one-dark.css";
  113. // import '../v-copy.js';
  114. // 键盘的shift键是否被按下
  115. let shiftKeyPressed = false
  116. export default {
  117. components:{
  118. marked
  119. },
  120. data() {
  121. return {
  122. diy_inputValue: '',
  123. is_up_img_file:false,
  124. import_list:[],
  125. is_show_import_img_view:false,
  126. is_open_relax:true,
  127. code:'',
  128. title: 'Hello',
  129. disabled: false,
  130. socketOpen:false,
  131. socketMsgQueue:[],
  132. recvMsgQueue:[],
  133. sendMsgQueue:[],
  134. inputValue: '',
  135. inputOldValue: '',
  136. _socketTask:null,
  137. scroll_text_:"\n",
  138. sendStatus:false,
  139. recvStatus:false,
  140. all_src_list:[],
  141. src_index:0,
  142. scroll_top:0,
  143. user_name:'ZYWZ', //用户名字
  144. ai_name:"SmartAssistant", //ai名字
  145. user_mobile:"18612220000",//用户手机号
  146. ani:'',
  147. ani_style:{
  148. width: "100upx",height: "100upx",rotate: 0,left:"25%",right:"25%",position:"absolute"
  149. },
  150. angle:359,
  151. imageUrl:'',
  152. fileData:null,
  153. cur_select_img:'../../static/import-img.png',
  154. }
  155. },
  156. mounted(){
  157. this.user_mobile = this.tools.get_user_info().mobile
  158. marked.setOptions({
  159. renderer: new marked.Renderer(),
  160. gfm: true,
  161. tables: true,
  162. breaks: false,
  163. pedantic: false,
  164. sanitize: false,
  165. smartLists: true,
  166. smartypants: false,
  167. highlight: function (code) {
  168. return hljs.highlightAuto(code).value;
  169. },
  170. langPrefix:"hljs language-"
  171. });
  172. },
  173. props: {
  174. viewTop: {
  175. type: Number,
  176. default: 0
  177. },
  178. viewHeight: {
  179. type: Number,
  180. default: 0
  181. }
  182. },
  183. methods: {
  184. send_diy_img(){
  185. if(this.cur_select_img==="../../static/import-img.png"){
  186. uni.showToast({
  187. title:"请选择图片"
  188. })
  189. return
  190. }
  191. if(this.diy_inputValue.length>0){
  192. this.is_show_import_img_view = false;
  193. let des_img = this.cur_select_img;
  194. this.sendSocketMessage(this.diy_inputValue,this.cur_select_img+" "+this.diy_inputValue,des_img)
  195. this.diy_inputValue = '';
  196. }else{
  197. uni.showToast({
  198. title:"请添加描述,只支持英文哦"
  199. })
  200. }
  201. },
  202. selectImg(path){
  203. let self = this;
  204. self.cur_select_img = path;
  205. },
  206. onFileInput(event) {
  207. let self = this;
  208. uni.chooseImage({
  209. success: (chooseImageRes) => {
  210. const tempFilePaths = chooseImageRes.tempFilePaths;
  211. self.is_up_img_file = true;
  212. uni.uploadFile({
  213. url: 'https://mlapi.hainanmlwl.com/file/upload_aiimg', //仅为示例,非真实的接口地址
  214. filePath: tempFilePaths[0],
  215. name: 'aiimg_url',
  216. formData: {
  217. // 'aiimg_url': self.cur_select_img
  218. },
  219. success: (uploadFileRes) => {
  220. self.is_up_img_file = false;
  221. let obj = JSON.parse(uploadFileRes.data)
  222. uni.showModal({
  223. content:obj.message,
  224. showCancel:false
  225. })
  226. console.log("self.cur_select_img",self.cur_select_img)
  227. if(obj.code==10000){
  228. let img_url = obj.content.surl
  229. self.import_list.push(img_url)
  230. self.cur_select_img = img_url;
  231. }
  232. console.log("uploadFile",obj);
  233. },
  234. fail() {
  235. uni.showModal({
  236. content:"上传失败",
  237. showCancel:false
  238. })
  239. self.is_up_img_file = false;
  240. }
  241. });
  242. }
  243. });
  244. // console.log("onFileInput",event)
  245. // const file = event.target.files[0] // 获取选择的文件
  246. // const reader = new FileReader() // 创建FileReader对象
  247. // // 当文件被读取时,将其转换为DataURL格式的字符串,并将其作为imageUrl值赋给组件的data属性中
  248. // reader.onload = (e) => {
  249. // this.imageUrl = e.target.result
  250. // // 保存文件对象到data属性中
  251. // this.fileData = file
  252. // }
  253. // reader.readAsDataURL(file) // 读取文件并启动onload回调函数
  254. },
  255. clickitem(action,image_id){
  256. switch(action){
  257. case "upsample1":
  258. break;
  259. case "upsample2":
  260. break;
  261. case "upsample3":
  262. break;
  263. case "upsample4":
  264. break;
  265. case "variation1":
  266. break;
  267. case "variation2":
  268. break;
  269. case "variation3":
  270. break;
  271. case "variation4":
  272. break;
  273. }
  274. console.log("clickitem",this.recvStatus,action,image_id)
  275. if(!this.recvStatus){
  276. this.sendSocketMessage(action,'','',action,image_id)
  277. }
  278. },
  279. getImg(index){
  280. return this.recvMsgQueue[index].msg_img
  281. },
  282. onclickdelete(){
  283. let self = this;
  284. if(self.recvMsgQueue.length>0&&self.recvMsgQueue[self.recvMsgQueue.length-1].isFinish){
  285. uni.showModal({
  286. showCancel:true,
  287. content:"是否删除记录",
  288. success:(res)=>{
  289. if(res.confirm){
  290. self.recvMsgQueue = []
  291. }
  292. }
  293. })
  294. }
  295. },
  296. // #ifdef H5 && VUE2
  297. onKeydown(keyname) {
  298. let self = this;
  299. if(self.inputOldValue!=self.inputValue){
  300. self.sendMsg();
  301. }else{
  302. }
  303. },
  304. onKeyup(keyname) {
  305. let self = this;
  306. self.inputOldValue=self.inputValue;
  307. },
  308. // #endif
  309. setCopy(content){
  310. // 使用#ifdef H5和#endif控制各端调用情况
  311. // 该方法不支持h5
  312. //#ifndef H5
  313. uni.setClipboardData({
  314. data: String(content), // 必须字符串
  315. success: function () {
  316. console.log('success');
  317. }
  318. });
  319. //#endif
  320. // h5端赋值方法,使用创建节点
  321. // #ifdef H5
  322. if (!document.queryCommandSupported('copy')) { // 兼容某些浏览器的判断
  323. console.log('该浏览器不支持')
  324. }
  325. let textarea = document.createElement("textarea")
  326. textarea.value = content
  327. textarea.readOnly = "readOnly"
  328. document.body.appendChild(textarea)
  329. textarea.select() // 选择对象
  330. textarea.setSelectionRange(0, content.length) // 核心
  331. let result = document.execCommand("copy") // 执行浏览器复制命令
  332. if (result) {
  333. uni.showToast({
  334. title: '复制成功',
  335. duration: 2000
  336. });
  337. }
  338. textarea.remove()
  339. // #endif
  340. },
  341. updateSrcList(){
  342. let self = this;
  343. let list = this.getIndexList(self.scroll_text_);
  344. for (var i = 0; i < list.length; i+=2) {
  345. let start = list[i];
  346. let end = list[i+1];
  347. self.all_src_list.push(self.scroll_text_.substring(start,end))
  348. }
  349. console.log("updateSrcList",self.all_src_list,self.scroll_text_)
  350. },
  351. stopRecv(){
  352. let self =this;
  353. self._socketTask.close()
  354. // self.initTcp(true);
  355. self.finish_recv();
  356. },
  357. handleClick(e) {
  358. e = e || window.event;
  359. let target = e.target || e.srcElement;
  360. let name = target.tagName.toLowerCase();
  361. let self =this;
  362. if(name.substring(0,3)=="abc"){
  363. let name_list = name.split('_');
  364. if(name_list.length>0){
  365. let index = parseInt(name_list[1])-1;
  366. console.log("handleClick",index,self.all_src_list)
  367. self.setCopy(self.all_src_list[index])
  368. }
  369. console.log("handleClick",self.all_src_list[index])
  370. console.log(target.tagName.toLowerCase())
  371. }
  372. console.log(name.substring(0,3))
  373. },
  374. copyUpdates(){
  375. let self = this;
  376. let str = self.recvMsgQueue[self.recvMsgQueue.length-1].msg_text
  377. let key = "</code></pre>";
  378. let index = self.all_src_list.length;
  379. while(str.indexOf(key) != -1){
  380. index++;
  381. let s_tag = "</code><abc_"+index+" class=\"copy-button\">Copy</abc_"+index+"></pre>"
  382. console.log("s_tag",s_tag)
  383. str=str.replace("</code></pre>", s_tag)
  384. }
  385. // str=str.replaceAll("</code></pre>", "</code><abc class=\"copy-button\">Copy</abc></pre>")
  386. self.recvMsgQueue[self.recvMsgQueue.length-1].msg_text = str
  387. // console.log("copyUpdates",str)
  388. self.$forceUpdate();
  389. },
  390. getIndexList(box_str){
  391. let box = box_str;
  392. let boxarr=[];
  393. let pos = box.indexOf('```');
  394. while(pos>-1){
  395. boxarr.push(pos);
  396. pos= box.indexOf('```',pos+1);
  397. }
  398. return boxarr
  399. },
  400. returnText(text){
  401. return "<style> body { background-color: black; color: white; } pre {position: relative;}.copy-button { position: absolute; top: 0;right: 0;padding: 4px 8px;background-color: #333;color: #fff;cursor: pointer;user-select: none;} p {line-height: 2;} li{line-height: 1.5;} table {border-collapse: collapse;width: 100%;font-family: Arial, sans-serif;font-size: 14px;}table th,table td {border: 1px solid #ddd;padding: 8px;text-align: left;}</style>" +text
  402. },
  403. // 滚动窗口以显示最新的一条消息
  404. showLastMsg() {
  405. let self = this;
  406. let container = uni.createSelectorQuery().in(this).select(".scroll-view-text");
  407. // 利用uniapp提供的接口获取可视区域的高度和滚动高度
  408. // let query=uni.createSelectorQuery()
  409. // let container=query.select('.box');
  410. container.fields({
  411. // rect:true, //是否返回节点布局位置信息{left,top,right,bottom}
  412. size:true, //是否返回节点尺寸信息{width,height}
  413. scrollOffset:true //是否返回节点滚动信息{scrollLeft,scrollTop}
  414. },(res)=>{
  415. self.scroll_top = res.height;
  416. // console.log(res)
  417. }).exec()
  418. },
  419. isAItell(type){
  420. if(type===config.type_ai){
  421. return true;
  422. }
  423. return false;
  424. },
  425. make_avatar(type){
  426. if(type===config.type_ai){
  427. return "../../static/PubImgs_avatar_avatar7.png";
  428. }
  429. return "../../static/PubImgs_avatar_avatar8.png";
  430. },
  431. isShow(text){
  432. return text!="";
  433. },
  434. initAni(){
  435. let self = this;
  436. if(!self.disabled){
  437. clearTimeout(self.initAni)
  438. return;
  439. }
  440. let loading_title = self.recvMsgQueue[self.recvMsgQueue.length-1].loading_title;
  441. let loading_title_str = ""
  442. for (var i = 0; i < loading_title; i++) {
  443. loading_title_str+="."
  444. }
  445. // console.log("loading_title_str",loading_title_str)
  446. self.recvMsgQueue[self.recvMsgQueue.length-1].msg_text ="正在生成" +loading_title_str;
  447. loading_title = loading_title>=3?0: (loading_title+1)
  448. self.recvMsgQueue[self.recvMsgQueue.length-1].loading_title = loading_title;
  449. setTimeout(self.initAni,1000)
  450. },
  451. async finish_recv(){
  452. let self = this;
  453. self.recvStatus = false;
  454. self.disabled = false;
  455. clearTimeout(self.initAni)
  456. self.scroll_text_+="\n"
  457. console.log("self.recvMsgQueue",self.scroll_text_)
  458. self.stopUpdateView();
  459. self.copyUpdates();
  460. self.updateSrcList();
  461. self.showLastMsg();
  462. self.recvMsgQueue[self.recvMsgQueue.length-1].isFinish = true;
  463. },
  464. async sendMsg(){
  465. // 如果内容为空
  466. if (!this.inputValue) {
  467. // 弹出提示框
  468. return uni.showToast({
  469. // 提示内容
  470. title: '内容不能为空',
  471. // 不显示图标
  472. icon: 'none'
  473. });
  474. }
  475. this.sendSocketMessage(this.inputValue)
  476. },
  477. onKeyInput(event) {
  478. // console.log("onKeyInput",event.target.value)
  479. let self = this;
  480. // self.inputOldValue=self.inputValue
  481. },
  482. startUpdateView(){
  483. let self = this;
  484. self.$forceUpdate();
  485. setTimeout(self.startUpdateView,500)
  486. },
  487. stopUpdateView(){
  488. let self = this;
  489. clearTimeout(self.startUpdateView)
  490. },
  491. sendSocketMessage(msg,prompt=msg,des_img='',action='generate',image_id='') {
  492. console.log("sendSocketMessage send",des_img)
  493. let self = this;
  494. let isRelax = self.is_open_relax;
  495. let token = isRelax?"7d995cf958f54d2c9c3264e645a9c4d9":"bdb957b8003e4a46b6b26a7174be5789";
  496. let relax = isRelax?"/relax" :"";
  497. let url = 'https://api.zhishuyun.com/midjourney/imagine' +relax +'?token='+token
  498. self.sendStatus = true;
  499. self.disabled = true;
  500. self.ani_style.rotate = 0;
  501. self.inputValue = '';
  502. self.recvMsgQueue.push({who_msg:config.type_self,msg_type:0,msg_text:msg,isFinish:true,'des_img':des_img})
  503. self.recvMsgQueue.push({who_msg:config.type_ai,msg_type:0,msg_text:"正在生成...",msg_img:"",isFinish:false,actions:[],image_id:"",task_id:"",loading_title:1})
  504. // self.recvMsgQueue[self.recvMsgQueue.length-1].actions=['upsample1', 'upsample2', 'upsample3', 'upsample4', 'variation1', 'variation2', 'variation3', 'variation4']
  505. self.initAni();
  506. uni.request({
  507. url:url,
  508. timeout:600000,
  509. header: {'Content-Type':'application/json','accept':'application/json'},
  510. method:'POST',
  511. data:{'prompt':prompt,'action':action,'image_id':image_id},
  512. success:(res)=>{
  513. self.finish_recv()
  514. if(res.statusCode===200){
  515. let html_img = '<!DOCTYPE html> <html><head></head><body> <img src='+res.data.image_url+ '></body></html>'
  516. self.recvMsgQueue[self.recvMsgQueue.length-1].msg_img = res.data.image_url;
  517. self.recvMsgQueue[self.recvMsgQueue.length-1].msg_text = "";
  518. self.recvMsgQueue[self.recvMsgQueue.length-1].image_id = res.data.image_id;
  519. console.log("res.data.actions",res.data.actions)
  520. self.recvMsgQueue[self.recvMsgQueue.length-1].actions = [];
  521. let list = [];
  522. list = res.data.actions;
  523. for (var i = 0; i < list.length; i++) {
  524. self.recvMsgQueue[self.recvMsgQueue.length-1].actions.push(list[i])
  525. }
  526. }else{
  527. uni.showModal({
  528. content:res.data.detail+":"+res.statusCode,
  529. showCancel:false
  530. })
  531. self.recvMsgQueue[self.recvMsgQueue.length-1].msg_text = res.data.detail;
  532. }
  533. console.log("Ai-view",res)
  534. },
  535. fail: (e) => {
  536. console.log('fail', e)
  537. self.finish_recv()
  538. self.recvMsgQueue[self.recvMsgQueue.length-1].msg_text ="生成失败";
  539. }
  540. })
  541. },
  542. }
  543. }
  544. </script>
  545. <style>
  546. .container{
  547. display: flex;
  548. box-sizing: border-box;
  549. flex-direction: column;
  550. position: fixed;
  551. /* position: relative; */
  552. /* background-color: #2A2832; */
  553. left: 0;
  554. width: 100%;
  555. justify-content: center;
  556. }
  557. .content {
  558. height: 100%;
  559. display: flex;
  560. flex-direction: column;
  561. align-items: center;
  562. justify-content: center;
  563. position: relative;
  564. background-color: #2A2832;
  565. }
  566. .text-area {
  567. display: flex;
  568. justify-content: center;
  569. }
  570. .title {
  571. font-size: 36rpx;
  572. color: #8f8f94;
  573. }
  574. .textarea-box,
  575. .textarea {
  576. width: 100%;
  577. height: 100%;
  578. margin-left: 3%;
  579. },
  580. textarea-box {
  581. width: 100% !important;
  582. }
  583. .textarea-box,
  584. .textarea,
  585. textarea,
  586. textarea-box {
  587. /* height: 120px; */
  588. }
  589. .textarea-box {
  590. background-color: #FFF;
  591. }
  592. uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
  593. display: none;
  594. width: 0 !important;
  595. height: 0 !important;
  596. -webkit-appearance: none;
  597. background: transparent;
  598. color: transparent;
  599. }
  600. </style>