makeImgDetail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  1. <template>
  2. <view class="makedetail-container">
  3. <view class="status-bar"></view>
  4. <!-- 顶部导航 -->
  5. <view class="nav-bar">
  6. <view class="left">
  7. <view class="uni-btn-icon" @click="goBack">&#xe601;</view>
  8. <view class="create">灵感创作</view>
  9. <image src="@/static/makedetail/cz_icon_lingganchuangzuo.png" class="edit"></image>
  10. </view>
  11. <view class="right">
  12. <view class="coinM">
  13. <image src="/static/icon/coin_m.png" mode="aspectFit"></image>
  14. <text>{{ myinfo.num_gmm }}</text>
  15. </view>
  16. <view class="coinC">
  17. <image src="/static/icon/coin_cd.png" mode="aspectFit"></image>
  18. <text>{{ myinfo.num_gmd }}</text>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 排队预览区域 -->
  23. <view class="preview-section lineUp-section" v-if="queuing">
  24. <view class="section-title">
  25. <text>创作预览</text>
  26. <view class="member-box">
  27. <image src="@/static/makedetail/wd_icon_vip(1).png" mode="aspectFit"></image>
  28. 升级会员插队加速
  29. </view>
  30. </view>
  31. <view class="preview-card">
  32. <image src="@/static/makedetail/cz_icon_jiazai.png" mode="aspectFit"></image>
  33. <view class="text1">排队中{{ queuePosition + '/' + allPosition }}</view>
  34. <view class="text2">退出不影响继续生成</view>
  35. </view>
  36. </view>
  37. <!-- 创作预览区域 -->
  38. <view class="preview-section" v-if="inQueue">
  39. <view class="section-title">创作预览</view>
  40. <view class="preview-card">
  41. <image src="@/static/makedetail/cz_icon_shengcheng.png" mode="aspectFit"></image>
  42. <view class="text1">生成中{{ progress }}%</view>
  43. <view class="text2">退出不影响继续生成</view>
  44. </view>
  45. </view>
  46. <!-- 以下区域在非排队状态下显示 -->
  47. <view>
  48. <!-- 创作描述输入区 -->
  49. <view class="description-section">
  50. <view class="section-header">
  51. <text class="section-title">创作描述<text style="display: none;" class="required">*</text></text>
  52. <view class="clear-text" @click="doYouWantToEdit() ? state() : clearDescription">
  53. <image src="/static/clear.png" mode="aspectFit"></image>
  54. <view class="clear-box">
  55. <image src="@/static/makedetail/cz_icon_qingkongwenben.png" class="edit"></image>
  56. <text>清空文本</text>
  57. </view>
  58. </view>
  59. </view>
  60. <textarea auto-height class="input-area" v-model="description" placeholder="请输入描述语,例如:穿着白色运动服,外表俊朗..."
  61. maxlength="1000" @input="onDescriptionInput" :disabled="doYouWantToEdit()"></textarea>
  62. <view class="word-count">{{ descriptionLength }}/1000</view>
  63. </view>
  64. <!-- 行为动作选择区 -->
  65. <view class="action-section">
  66. <view class="section-title">行为动作</view>
  67. <input :disabled="doYouWantToEdit()" class="input-box" v-model="action" placeholder="可输入也可点击推荐词" />
  68. <view class="tag-group">
  69. <text class="tag" v-for="(item, index) in actionTags" :key="index"
  70. @click="doYouWantToEdit() ? state() : selectAction(item)" :class="{ active: action == item }">{{
  71. item }}</text>
  72. </view>
  73. </view>
  74. <!-- 主体环境选择区 -->
  75. <view class="environment-section">
  76. <view class="section-title">主体环境</view>
  77. <input class="input-box" v-model="environment" :disabled="doYouWantToEdit()" placeholder="可输入也可点击推荐词" />
  78. <view class="tag-group">
  79. <text class="tag" v-for="(item, index) in environmentTags" :key="index"
  80. @click="doYouWantToEdit() ? state() : selectEnvironment(item)"
  81. :class="{ active: environment == item }">{{ item }}</text>
  82. </view>
  83. </view>
  84. <!-- 主体形象选择区 -->
  85. <view class="image-section">
  86. <view class="section-title">主体形象</view>
  87. <input class="input-box" v-model="image" :disabled="doYouWantToEdit()" placeholder="可输入也可点击推荐词" />
  88. <view class="tag-group">
  89. <text class="tag" v-for="(item, index) in imageTags" :key="index"
  90. @click="doYouWantToEdit() ? state() : selectImage(item)" :class="{ active: image == item }">{{
  91. item
  92. }}</text>
  93. </view>
  94. </view>
  95. <!-- 参考风格选择区 -->
  96. <view class="style-section">
  97. <view class="section-title">选择参考风格<text style="display: none;" class="required">*</text></view>
  98. <scroll-view class="style-scroll" scroll-x>
  99. <view class="style-item" v-for="(item, index) in styleList" :key="index"
  100. :class="{ 'active': selectedStyle === index }"
  101. @click="doYouWantToEdit() ? state() : selectStyle(index)">
  102. <image :src="item.image" mode="aspectFill"></image>
  103. <text>{{ item.name }}</text>
  104. </view>
  105. </scroll-view>
  106. </view>
  107. <!-- 底部按钮 -->
  108. <view class="bottom-button">
  109. <button v-if="doYouWantToEdit" class="generate-btn" @click="generateImage">立即生成
  110. <image src="/static/icon/coin_cd.png" mode="aspectFit"></image>
  111. 10
  112. </button>
  113. <view v-else class="generate-btn prohibit">生成中
  114. </view>
  115. <view class="promotion-link">
  116. <image class="vip" src="/static/makedetail/wd_icon_vip(1).png" mode="aspectFit"></image>
  117. <text> 即刻开通订阅,获取各种福利! </text>
  118. <image class="jiantou" src="/static/makedetail/cz_icon_jiantou.png" mode="aspectFit"></image>
  119. </view>
  120. </view>
  121. </view>
  122. <!-- 新手引导组件 -->
  123. <novice-guidance :step="step"></novice-guidance>
  124. </view>
  125. </template>
  126. <script>
  127. export default {
  128. data() {
  129. return {
  130. queuePosition: '0',
  131. allPosition: '0',
  132. progress: '', //创作进度
  133. description: '',
  134. descriptionLength: 0,
  135. action: '',
  136. environment: '',
  137. image: '',
  138. selectedStyle: -1,
  139. actionTags: ['跳舞', '开枪', '喝咖啡', '看书', '运动'],
  140. environmentTags: ['都市大道', '大树底下', '办公室', '厨房'],
  141. imageTags: ['戴着墨镜', '戴着耳机', '戴着帽子', '手持冲浪板'],
  142. styleList: [{
  143. name: '自然共生',
  144. image: '../../static/dome/fenge.png'
  145. },
  146. {
  147. name: '国风新锋',
  148. image: '../../static/dome/fenge.png'
  149. },
  150. {
  151. name: '萌系治愈',
  152. image: '../../static/dome/fenge.png'
  153. },
  154. {
  155. name: '萌系治愈',
  156. image: '../../static/dome/fenge.png'
  157. },
  158. {
  159. name: '萌系治愈',
  160. image: '../../static/dome/fenge.png'
  161. }
  162. ],
  163. inQueue: false,//是否创作中
  164. queuing: false,//是否排队中
  165. queueMessage: '',
  166. myinfo: {},
  167. step: {
  168. name: "makeImgGuide",
  169. guideList: [
  170. {
  171. el: ".right",
  172. tips: "积分可在这里查看,每日签到可获得积分!",
  173. next: "知道了",
  174. // style: "width: 120px; left: 490rpx;"
  175. },
  176. {
  177. el: ".input-area",
  178. tips: "输入关键词,描述我想要的画面!",
  179. next: "知道了",
  180. },
  181. {
  182. el: ".action-section",
  183. tips: "选择或输入主体的行为动作!",
  184. next: "知道了",
  185. },
  186. {
  187. el: ".environment-section",
  188. tips: "选择或输入主体所处的环境场景",
  189. next: "知道了",
  190. },
  191. {
  192. el: ".image-section",
  193. tips: "选择或输入主体形象特征",
  194. next: "知道了",
  195. },
  196. {
  197. el: ".style-scroll",
  198. tips: "选择您喜欢的参考风格",
  199. next: "知道了",
  200. },
  201. {
  202. el: ".generate-btn",
  203. tips: "点击这里开始生成您的图片作品",
  204. next: "完成",
  205. }]
  206. }
  207. }
  208. },
  209. onLoad(e) {
  210. // this.checkQueueStatus()
  211. this.getMyInfo();
  212. if (e.id) {
  213. this.getQueueDetail(e.id)
  214. }
  215. },
  216. methods: {
  217. doYouWantToEdit() {
  218. return this.inQueue || this.queuing
  219. },
  220. state() {
  221. if (this.inQueue) {
  222. uni.showToast({
  223. title: '正在创作中无法修改',
  224. icon: 'none'
  225. })
  226. } else if (this.queuing) {
  227. uni.showToast({
  228. title: '正在排队中无法修改',
  229. icon: 'none'
  230. })
  231. }
  232. },
  233. goBack() {
  234. uni.navigateBack()
  235. },
  236. getMyInfo() {
  237. uni.request({
  238. url: this.$apiHost + '/My/getnum',
  239. method: 'GET',
  240. header: {
  241. 'content-type': 'application/json',
  242. 'sign': getApp().globalData.headerSign
  243. },
  244. data: {
  245. uuid: getApp().globalData.uuid
  246. },
  247. success: (res) => {
  248. console.log("获取用户信息:", res.data);
  249. this.myinfo = res.data
  250. }
  251. })
  252. },
  253. checkQueueStatus() {
  254. uni.request({
  255. url: this.$apiHost + '/WorkAI/queueStatus',
  256. method: 'GET',
  257. header: {
  258. 'Content-Type': 'application/x-www-form-urlencoded',
  259. 'sign': getApp().globalData.headerSign
  260. },
  261. data: {
  262. uuid: getApp().globalData.uuid,
  263. task_type: 1
  264. },
  265. success: (res) => {
  266. console.log("队列状态:", res.data);
  267. if (res.data.success === "yes") {
  268. this.inQueue = res.data.in_queue
  269. if (this.inQueue) {
  270. this.queueMessage = res.data.str
  271. }
  272. }
  273. },
  274. fail: (err) => {
  275. console.log('获取队列状态失败:', err);
  276. uni.showToast({
  277. title: '获取状态失败',
  278. icon: 'none'
  279. });
  280. }
  281. })
  282. },
  283. clearDescription() {
  284. this.description = ''
  285. this.descriptionLength = 0
  286. },
  287. onDescriptionInput(e) {
  288. this.descriptionLength = e.detail.value.length
  289. },
  290. selectAction(tag) {
  291. this.action = tag
  292. },
  293. selectEnvironment(tag) {
  294. this.environment = tag
  295. },
  296. selectImage(tag) {
  297. this.image = tag
  298. },
  299. selectStyle(index) {
  300. this.selectedStyle = index
  301. },
  302. generateImage() {
  303. if (!this.description) {
  304. uni.showToast({
  305. title: '请输入创作描述',
  306. icon: 'none'
  307. })
  308. return
  309. }
  310. // if (this.selectedStyle === -1) {
  311. // uni.showToast({
  312. // title: '请选择参考风格',
  313. // icon: 'none'
  314. // })
  315. // return
  316. // }
  317. let style = '';
  318. if (this.selectedStyle !== -1) {
  319. style = this.styleList[this.selectedStyle].name
  320. }
  321. let that = this
  322. uni.request({
  323. url: this.$apiHost + '/WorkAI/creatorLG',
  324. data: {
  325. uuid: getApp().globalData.uuid,
  326. description: this.description,
  327. action: this.action,
  328. environment: this.environment,
  329. subject: this.image,
  330. style: style
  331. },
  332. method: 'POST',
  333. header: {
  334. 'Content-Type': 'application/x-www-form-urlencoded',
  335. 'sign': getApp().globalData.headerSign
  336. },
  337. dataType: 'json',
  338. success: (res) => {
  339. console.log("生成结果:", res.data);
  340. uni.showToast({
  341. title: res.data.str || '请求成功',
  342. icon: 'none'
  343. });
  344. if (res.data.success == "yes") {
  345. // TODO: 处理生成成功后的逻辑
  346. setTimeout(function () {
  347. // that.checkQueueStatus()
  348. uni.navigateBack()
  349. }, 500);
  350. }
  351. },
  352. fail: (err) => {
  353. console.log('生成失败:', err);
  354. uni.showToast({
  355. title: '生成请求失败',
  356. icon: 'none'
  357. });
  358. }
  359. })
  360. },
  361. getQueueDetail(id) {
  362. if (!id) {
  363. return
  364. }
  365. let that = this
  366. uni.request({
  367. url: this.$apiHost + '/WorkAI/getQueueDetail',
  368. data: {
  369. uuid: getApp().globalData.uuid,
  370. id: id
  371. },
  372. header: {
  373. 'Content-Type': 'application/x-www-form-urlencoded',
  374. 'sign': getApp().globalData.headerSign
  375. },
  376. dataType: 'json',
  377. success: (res) => {
  378. console.log("查询单个结果:", res.data);
  379. if (res.data.success == "yes") {
  380. var { queuePosition, allPosition, progress, description, action, environment, environment, style } = res.data.data
  381. that.queuePosition = queuePosition
  382. that.allPosition = allPosition
  383. that.progress = progress
  384. that.description = description
  385. that.action = action
  386. that.environment = environment
  387. that.selectedStyle = that.styleList.findIndex(item => item.name == style)
  388. if (queuePosition == allPosition) {
  389. // 创作中逻辑
  390. that.inQueue = true
  391. } else if (queuePosition < allPosition) {
  392. // 排队中逻辑
  393. that.queuing = true
  394. }
  395. }
  396. },
  397. fail: (err) => {
  398. console.log('查询失败失败:', err);
  399. uni.showToast({
  400. title: '查询失败请求失败',
  401. icon: 'none'
  402. });
  403. }
  404. })
  405. }
  406. }
  407. }
  408. </script>
  409. <style lang="scss">
  410. @import './makeImgDetail.scss';
  411. </style>