makeImgDetail.vue 13 KB

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