makeImgDetail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385
  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. </view>
  123. </template>
  124. <script>
  125. export default {
  126. data() {
  127. return {
  128. queuePosition: '0',
  129. allPosition: '0',
  130. progress: '', //创作进度
  131. description: '',
  132. descriptionLength: 0,
  133. action: '',
  134. environment: '',
  135. image: '',
  136. selectedStyle: -1,
  137. actionTags: ['跳舞', '开枪', '喝咖啡', '看书', '运动'],
  138. environmentTags: ['都市大道', '大树底下', '办公室', '厨房'],
  139. imageTags: ['戴着墨镜', '戴着耳机', '戴着帽子', '手持冲浪板'],
  140. styleList: [{
  141. name: '自然共生',
  142. image: '../../static/dome/fenge.png'
  143. },
  144. {
  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. inQueue: false,//是否创作中
  162. queuing: false,//是否排队中
  163. queueMessage: '',
  164. myinfo: {}
  165. }
  166. },
  167. onLoad(e) {
  168. // this.checkQueueStatus()
  169. this.getMyInfo();
  170. if (e.id) {
  171. this.getQueueDetail(e.id)
  172. }
  173. },
  174. methods: {
  175. doYouWantToEdit() {
  176. return this.inQueue || this.queuing
  177. },
  178. state() {
  179. if (this.inQueue) {
  180. uni.showToast({
  181. title: '正在创作中无法修改',
  182. icon: 'none'
  183. })
  184. } else if (this.queuing) {
  185. uni.showToast({
  186. title: '正在排队中无法修改',
  187. icon: 'none'
  188. })
  189. }
  190. },
  191. goBack() {
  192. uni.navigateBack()
  193. },
  194. getMyInfo() {
  195. uni.request({
  196. url: this.$apiHost + '/My/getnum',
  197. method: 'GET',
  198. header: {
  199. 'content-type': 'application/json',
  200. 'sign': getApp().globalData.headerSign
  201. },
  202. data: {
  203. uuid: getApp().globalData.uuid
  204. },
  205. success: (res) => {
  206. console.log("获取用户信息:", res.data);
  207. this.myinfo = res.data
  208. }
  209. })
  210. },
  211. checkQueueStatus() {
  212. uni.request({
  213. url: this.$apiHost + '/WorkAI/queueStatus',
  214. method: 'GET',
  215. header: {
  216. 'Content-Type': 'application/x-www-form-urlencoded',
  217. 'sign': getApp().globalData.headerSign
  218. },
  219. data: {
  220. uuid: getApp().globalData.uuid,
  221. task_type: 1
  222. },
  223. success: (res) => {
  224. console.log("队列状态:", res.data);
  225. if (res.data.success === "yes") {
  226. this.inQueue = res.data.in_queue
  227. if (this.inQueue) {
  228. this.queueMessage = res.data.str
  229. }
  230. }
  231. },
  232. fail: (err) => {
  233. console.log('获取队列状态失败:', err);
  234. uni.showToast({
  235. title: '获取状态失败',
  236. icon: 'none'
  237. });
  238. }
  239. })
  240. },
  241. clearDescription() {
  242. this.description = ''
  243. this.descriptionLength = 0
  244. },
  245. onDescriptionInput(e) {
  246. this.descriptionLength = e.detail.value.length
  247. },
  248. selectAction(tag) {
  249. this.action = tag
  250. },
  251. selectEnvironment(tag) {
  252. this.environment = tag
  253. },
  254. selectImage(tag) {
  255. this.image = tag
  256. },
  257. selectStyle(index) {
  258. this.selectedStyle = index
  259. },
  260. generateImage() {
  261. if (!this.description) {
  262. uni.showToast({
  263. title: '请输入创作描述',
  264. icon: 'none'
  265. })
  266. return
  267. }
  268. // if (this.selectedStyle === -1) {
  269. // uni.showToast({
  270. // title: '请选择参考风格',
  271. // icon: 'none'
  272. // })
  273. // return
  274. // }
  275. let style = '';
  276. if (this.selectedStyle !== -1) {
  277. style = this.styleList[this.selectedStyle].name
  278. }
  279. let that = this
  280. uni.request({
  281. url: this.$apiHost + '/WorkAI/creatorLG',
  282. data: {
  283. uuid: getApp().globalData.uuid,
  284. description: this.description,
  285. action: this.action,
  286. environment: this.environment,
  287. subject: this.image,
  288. style: style
  289. },
  290. method: 'POST',
  291. header: {
  292. 'Content-Type': 'application/x-www-form-urlencoded',
  293. 'sign': getApp().globalData.headerSign
  294. },
  295. dataType: 'json',
  296. success: (res) => {
  297. console.log("生成结果:", res.data);
  298. uni.showToast({
  299. title: res.data.str || '请求成功',
  300. icon: 'none'
  301. });
  302. if (res.data.success == "yes") {
  303. // TODO: 处理生成成功后的逻辑
  304. setTimeout(function () {
  305. // that.checkQueueStatus()
  306. uni.navigateBack()
  307. }, 500);
  308. }
  309. },
  310. fail: (err) => {
  311. console.log('生成失败:', err);
  312. uni.showToast({
  313. title: '生成请求失败',
  314. icon: 'none'
  315. });
  316. }
  317. })
  318. },
  319. getQueueDetail(id) {
  320. if (!id) {
  321. return
  322. }
  323. let that = this
  324. uni.request({
  325. url: this.$apiHost + '/WorkAI/getQueueDetail',
  326. data: {
  327. uuid: getApp().globalData.uuid,
  328. id: id
  329. },
  330. header: {
  331. 'Content-Type': 'application/x-www-form-urlencoded',
  332. 'sign': getApp().globalData.headerSign
  333. },
  334. dataType: 'json',
  335. success: (res) => {
  336. console.log("查询单个结果:", res.data);
  337. if (res.data.success == "yes") {
  338. var { queuePosition, allPosition, progress, description, action, environment, environment, style } = res.data.data
  339. that.queuePosition = queuePosition
  340. that.allPosition = allPosition
  341. that.progress = progress
  342. that.description = description
  343. that.action = action
  344. that.environment = environment
  345. that.selectedStyle = that.styleList.findIndex(item => item.name == style)
  346. if (queuePosition == allPosition) {
  347. // 创作中逻辑
  348. that.inQueue = true
  349. } else if (queuePosition < allPosition) {
  350. // 排队中逻辑
  351. that.queuing = true
  352. }
  353. }
  354. },
  355. fail: (err) => {
  356. console.log('查询失败失败:', err);
  357. uni.showToast({
  358. title: '查询失败请求失败',
  359. icon: 'none'
  360. });
  361. }
  362. })
  363. }
  364. }
  365. }
  366. </script>
  367. <style lang="scss">
  368. @import './makeImgDetail.scss';
  369. </style>