makeImgDetail.vue 12 KB

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