makeImgDetail.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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>
  50. <!-- 创作描述输入区 -->
  51. <view class="description-section">
  52. <view class="section-header">
  53. <text class="section-title">创作描述<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. <image :src="item.image" mode="aspectFill"></image>
  105. <text>{{ item.name }}</text>
  106. </view>
  107. </scroll-view>
  108. </view>
  109. <!-- 底部按钮 -->
  110. <view class="bottom-button">
  111. <button v-if="doYouWantToEdit" class="generate-btn" @click="generateImage">立即生成
  112. <image src="/static/icon/coin_cd.png" mode="aspectFit"></image>
  113. 10
  114. </button>
  115. <view v-else class="generate-btn prohibit">生成中
  116. </view>
  117. <view v-if="isRecharge" class="promotion-link" @click="goPage('/pages/vip/index')">
  118. <image class="vip" src="/static/makedetail/wd_icon_vip(1).png" mode="aspectFit"></image>
  119. <text> 即刻开通订阅,获取各种福利! </text>
  120. <image class="jiantou" src="/static/makedetail/cz_icon_jiantou.png" mode="aspectFit"></image>
  121. </view>
  122. </view>
  123. </view>
  124. <!-- 新手引导组件 -->
  125. <novice-guidance :step="step" v-if="isGuiding"></novice-guidance>
  126. </view>
  127. </template>
  128. <script>
  129. import { mapState } from 'vuex'
  130. export default {
  131. data() {
  132. return {
  133. queuePosition: '0',
  134. allPosition: '0',
  135. progress: '', //创作进度
  136. description: '',
  137. descriptionLength: 0,
  138. action: '',
  139. environment: '',
  140. image: '',
  141. selectedStyle: -1,
  142. actionTags: ['跳舞', '唱歌', '喝咖啡', '看书', '运动'],
  143. environmentTags: ['都市大道', '大树底下', '办公室', '厨房'],
  144. imageTags: ['戴着墨镜', '戴着耳机', '戴着帽子', '手持冲浪板'],
  145. styleList: [{
  146. name: '自然共生',
  147. image: '../../static/dome/fenge.png'
  148. },
  149. {
  150. name: '国风新锋',
  151. image: '../../static/dome/fenge.png'
  152. },
  153. {
  154. name: '萌系治愈',
  155. image: '../../static/dome/fenge.png'
  156. },
  157. {
  158. name: '萌系治愈',
  159. image: '../../static/dome/fenge.png'
  160. },
  161. {
  162. name: '萌系治愈',
  163. image: '../../static/dome/fenge.png'
  164. }
  165. ],
  166. inQueue: false,//是否创作中
  167. queuing: false,//是否排队中
  168. queueMessage: '',
  169. myinfo: {},
  170. step: {
  171. name: "makeImgGuide",
  172. guideList: [
  173. {
  174. el: ".right",
  175. tips: "积分可在这里查看,每日签到可获得积分!",
  176. next: "知道了",
  177. // style: "width: 120px; left: 490rpx;"
  178. },
  179. {
  180. el: ".input-area",
  181. tips: "输入关键词,描述我想要的画面!",
  182. next: "知道了",
  183. },
  184. {
  185. el: ".action-section",
  186. tips: "选择或输入主体的行为动作!",
  187. next: "知道了",
  188. },
  189. {
  190. el: ".environment-section",
  191. tips: "选择或输入主体所处的环境场景",
  192. next: "知道了",
  193. },
  194. {
  195. el: ".image-section",
  196. tips: "选择或输入主体形象特征",
  197. next: "知道了",
  198. },
  199. {
  200. el: ".style-scroll",
  201. tips: "选择您喜欢的参考风格",
  202. next: "知道了",
  203. },
  204. {
  205. el: ".generate-btn",
  206. tips: "点击这里开始生成您的图片作品",
  207. next: "完成",
  208. }]
  209. }
  210. }
  211. },
  212. computed: {
  213. ...mapState('switchingModule', ['isRecharge', 'isGuiding'])
  214. },
  215. onLoad(e) {
  216. // this.checkQueueStatus()
  217. this.getMyInfo();
  218. if (e.id) {
  219. this.getQueueDetail(e.id)
  220. }
  221. },
  222. methods: {
  223. doYouWantToEdit() {
  224. return this.inQueue || this.queuing
  225. },
  226. state() {
  227. if (this.inQueue) {
  228. uni.showToast({
  229. title: '正在创作中无法修改',
  230. icon: 'none'
  231. })
  232. } else if (this.queuing) {
  233. uni.showToast({
  234. title: '正在排队中无法修改',
  235. icon: 'none'
  236. })
  237. }
  238. },
  239. goBack() {
  240. uni.navigateBack()
  241. },
  242. getMyInfo() {
  243. uni.request({
  244. url: this.$apiHost + '/My/getnum',
  245. method: 'GET',
  246. header: {
  247. 'content-type': 'application/json',
  248. 'sign': getApp().globalData.headerSign
  249. },
  250. data: {
  251. uuid: getApp().globalData.uuid
  252. },
  253. success: (res) => {
  254. console.log("获取用户信息:", res.data);
  255. this.myinfo = res.data
  256. }
  257. })
  258. },
  259. checkQueueStatus() {
  260. uni.request({
  261. url: this.$apiHost + '/WorkAI/queueStatus',
  262. method: 'GET',
  263. header: {
  264. 'Content-Type': 'application/x-www-form-urlencoded',
  265. 'sign': getApp().globalData.headerSign
  266. },
  267. data: {
  268. uuid: getApp().globalData.uuid,
  269. task_type: 1
  270. },
  271. success: (res) => {
  272. console.log("队列状态:", res.data);
  273. if (res.data.success === "yes") {
  274. this.inQueue = res.data.in_queue
  275. if (this.inQueue) {
  276. this.queueMessage = res.data.str
  277. }
  278. }
  279. },
  280. fail: (err) => {
  281. console.log('获取队列状态失败:', err);
  282. uni.showToast({
  283. title: '获取状态失败',
  284. icon: 'none'
  285. });
  286. }
  287. })
  288. },
  289. clearDescription() {
  290. this.description = ''
  291. this.descriptionLength = 0
  292. },
  293. onDescriptionInput(e) {
  294. this.descriptionLength = e.detail.value.length
  295. },
  296. selectAction(tag) {
  297. this.action = tag
  298. },
  299. selectEnvironment(tag) {
  300. this.environment = tag
  301. },
  302. selectImage(tag) {
  303. this.image = tag
  304. },
  305. selectStyle(index) {
  306. this.selectedStyle = index
  307. },
  308. generateImage() {
  309. if (!this.description) {
  310. uni.showToast({
  311. title: '请输入创作描述',
  312. icon: 'none'
  313. })
  314. return
  315. }
  316. // if (this.selectedStyle === -1) {
  317. // uni.showToast({
  318. // title: '请选择参考风格',
  319. // icon: 'none'
  320. // })
  321. // return
  322. // }
  323. let style = '';
  324. if (this.selectedStyle !== -1) {
  325. style = this.styleList[this.selectedStyle].name
  326. }
  327. let that = this
  328. uni.request({
  329. url: this.$apiHost + '/WorkAI/creatorLG',
  330. data: {
  331. uuid: getApp().globalData.uuid,
  332. description: this.description,
  333. action: this.action,
  334. environment: this.environment,
  335. subject: this.image,
  336. style: style
  337. },
  338. method: 'POST',
  339. header: {
  340. 'Content-Type': 'application/x-www-form-urlencoded',
  341. 'sign': getApp().globalData.headerSign
  342. },
  343. dataType: 'json',
  344. success: (res) => {
  345. console.log("生成结果:", res.data);
  346. uni.showToast({
  347. title: res.data.str || '请求成功',
  348. icon: 'none'
  349. });
  350. if (res.data.success == "yes") {
  351. // TODO: 处理生成成功后的逻辑
  352. setTimeout(function () {
  353. // that.checkQueueStatus()
  354. // uni.navigateBack()
  355. // 使用全局变量存储状态
  356. getApp().globalData.needSwitchToGenerating = true;
  357. uni.switchTab({ url: '/pages/my/my' });
  358. }, 1500);
  359. }
  360. },
  361. fail: (err) => {
  362. console.log('生成失败:', err);
  363. uni.showToast({
  364. title: '生成请求失败',
  365. icon: 'none'
  366. });
  367. }
  368. })
  369. },
  370. getQueueDetail(id) {
  371. if (!id) {
  372. return
  373. }
  374. let that = this
  375. uni.request({
  376. url: this.$apiHost + '/WorkAI/getQueueDetail',
  377. data: {
  378. uuid: getApp().globalData.uuid,
  379. id: id
  380. },
  381. header: {
  382. 'Content-Type': 'application/x-www-form-urlencoded',
  383. 'sign': getApp().globalData.headerSign
  384. },
  385. dataType: 'json',
  386. success: (res) => {
  387. console.log("查询单个结果:", res.data);
  388. if (res.data.success == "yes") {
  389. var { queuePosition, allPosition, progress, description, action, environment, environment, style } = res.data.data
  390. that.queuePosition = queuePosition
  391. that.allPosition = allPosition
  392. that.progress = progress
  393. that.description = description
  394. that.action = action
  395. that.environment = environment
  396. that.selectedStyle = that.styleList.findIndex(item => item.name == style)
  397. if (queuePosition == allPosition) {
  398. // 创作中逻辑
  399. that.inQueue = true
  400. } else if (queuePosition < allPosition) {
  401. // 排队中逻辑
  402. that.queuing = true
  403. }
  404. }
  405. },
  406. fail: (err) => {
  407. console.log('查询失败失败:', err);
  408. uni.showToast({
  409. title: '查询失败请求失败',
  410. icon: 'none'
  411. });
  412. }
  413. })
  414. },
  415. goPage(page) {
  416. uni.navigateTo({
  417. url: page,
  418. });
  419. },
  420. }
  421. }
  422. </script>
  423. <style lang="scss">
  424. @import './makeImgDetail.scss';
  425. </style>