makeImgDetail.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. <template>
  2. <view class="makedetail-container">
  3. <!-- 顶部导航 -->
  4. <view class="nav-bar">
  5. <view class="left">
  6. <view class="uni-btn-icon" @click="goBack">&#xe601;</view>
  7. </view>
  8. <view class="center">发表创作</view>
  9. <view class="right">
  10. <view class="coinM">
  11. <image src="/static/icon/coin_m.png" mode="aspectFit"></image>
  12. <text>{{myinfo.num_gmm}}</text>
  13. </view>
  14. <view class="coinC">
  15. <image src="/static/icon/coin_cd.png" mode="aspectFit"></image>
  16. <text>{{myinfo.num_gmd}}</text>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 创作预览区域 -->
  21. <view class="preview-section" v-if="inQueue">
  22. <view class="preview-title">创作预览</view>
  23. <view class="preview-card">
  24. <image class="loading-icon" src="/static/loading.png" mode="aspectFit"></image>
  25. <text class="loading-text">{{queueMessage}}</text>
  26. <text class="sub-text">请耐心等待制作完成</text>
  27. </view>
  28. </view>
  29. <!-- 以下区域在非排队状态下显示 -->
  30. <view v-if="!inQueue">
  31. <!-- 创作描述输入区 -->
  32. <view class="description-section">
  33. <view class="section-header">
  34. <text class="section-title">创作描述<text class="required">*</text></text>
  35. <view class="clear-text" @click="clearDescription">
  36. <image src="/static/clear.png" mode="aspectFit"></image>
  37. <text>清空文本</text>
  38. </view>
  39. </view>
  40. <textarea class="input-area" v-model="description" placeholder="请输入描述语,例如:穿着白色运动服,外表俊朗..."
  41. maxlength="1000" @input="onDescriptionInput"></textarea>
  42. <view class="word-count">{{descriptionLength}}/1000</view>
  43. </view>
  44. <!-- 行为动作选择区 -->
  45. <view class="action-section">
  46. <view class="section-title">行为动作</view>
  47. <input class="input-box" v-model="action" placeholder="可输入也可点击推荐词" />
  48. <view class="tag-group">
  49. <text class="tag" v-for="(item, index) in actionTags" :key="index"
  50. @click="selectAction(item)">{{item}}</text>
  51. </view>
  52. </view>
  53. <!-- 主体环境选择区 -->
  54. <view class="environment-section">
  55. <view class="section-title">主体环境</view>
  56. <input class="input-box" v-model="environment" placeholder="可输入也可点击推荐词" />
  57. <view class="tag-group">
  58. <text class="tag" v-for="(item, index) in environmentTags" :key="index"
  59. @click="selectEnvironment(item)">{{item}}</text>
  60. </view>
  61. </view>
  62. <!-- 主体形象选择区 -->
  63. <view class="image-section">
  64. <view class="section-title">主体形象</view>
  65. <input class="input-box" v-model="image" placeholder="可输入也可点击推荐词" />
  66. <view class="tag-group">
  67. <text class="tag" v-for="(item, index) in imageTags" :key="index"
  68. @click="selectImage(item)">{{item}}</text>
  69. </view>
  70. </view>
  71. <!-- 参考风格选择区 -->
  72. <view class="style-section">
  73. <view class="section-title">选择参考风格<text class="required">*</text></view>
  74. <scroll-view class="style-scroll" scroll-x>
  75. <view class="style-item" v-for="(item, index) in styleList" :key="index"
  76. :class="{'active': selectedStyle === index}" @click="selectStyle(index)">
  77. <image :src="item.image" mode="aspectFill"></image>
  78. <text>{{item.name}}</text>
  79. </view>
  80. </scroll-view>
  81. </view>
  82. <!-- 底部按钮 -->
  83. <view class="bottom-button">
  84. <button class="generate-btn" @click="generateImage">立即生成(消耗10贡献)</button>
  85. <view class="promotion-link">
  86. <text> 即刻开通订阅,获取各种福利! </text>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </template>
  92. <script>
  93. export default {
  94. data() {
  95. return {
  96. description: '',
  97. descriptionLength: 0,
  98. action: '',
  99. environment: '',
  100. image: '',
  101. selectedStyle: -1,
  102. actionTags: ['跳舞', '开枪', '喝咖啡', '看书', '运动'],
  103. environmentTags: ['都市大道', '大树底下', '办公室', '厨房'],
  104. imageTags: ['戴着墨镜', '戴着耳机', '戴着帽子', '手持冲浪板'],
  105. styleList: [{
  106. name: '自然共生',
  107. image: '/static/style1.png'
  108. },
  109. {
  110. name: '国风新锋',
  111. image: '/static/style2.png'
  112. },
  113. {
  114. name: '萌系治愈',
  115. image: '/static/style3.png'
  116. }
  117. ],
  118. inQueue: false,
  119. queueMessage: '',
  120. myinfo: {}
  121. }
  122. },
  123. onLoad() {
  124. // this.checkQueueStatus()
  125. this.getMyInfo();
  126. },
  127. methods: {
  128. goBack() {
  129. uni.navigateBack()
  130. },
  131. getMyInfo() {
  132. uni.request({
  133. url: this.$apiHost + '/My/getnum',
  134. method: 'GET',
  135. header: {
  136. 'content-type': 'application/json',
  137. 'sign': getApp().globalData.headerSign
  138. },
  139. data: {
  140. uuid: getApp().globalData.uuid
  141. },
  142. success: (res) => {
  143. console.log("获取用户信息:", res.data);
  144. this.myinfo = res.data
  145. }
  146. })
  147. },
  148. checkQueueStatus() {
  149. uni.request({
  150. url: this.$apiHost + '/WorkAI/queueStatus',
  151. method: 'GET',
  152. header: {
  153. 'Content-Type': 'application/x-www-form-urlencoded',
  154. 'sign': getApp().globalData.headerSign
  155. },
  156. data: {
  157. uuid: getApp().globalData.uuid,
  158. task_type: 1
  159. },
  160. success: (res) => {
  161. console.log("队列状态:", res.data);
  162. if (res.data.success === "yes") {
  163. this.inQueue = res.data.in_queue
  164. if (this.inQueue) {
  165. this.queueMessage = res.data.str
  166. }
  167. }
  168. },
  169. fail: (err) => {
  170. console.log('获取队列状态失败:', err);
  171. uni.showToast({
  172. title: '获取状态失败',
  173. icon: 'none'
  174. });
  175. }
  176. })
  177. },
  178. clearDescription() {
  179. this.description = ''
  180. this.descriptionLength = 0
  181. },
  182. onDescriptionInput(e) {
  183. this.descriptionLength = e.detail.value.length
  184. },
  185. selectAction(tag) {
  186. this.action = tag
  187. },
  188. selectEnvironment(tag) {
  189. this.environment = tag
  190. },
  191. selectImage(tag) {
  192. this.image = tag
  193. },
  194. selectStyle(index) {
  195. this.selectedStyle = index
  196. },
  197. generateImage() {
  198. if (!this.description) {
  199. uni.showToast({
  200. title: '请输入创作描述',
  201. icon: 'none'
  202. })
  203. return
  204. }
  205. // if (this.selectedStyle === -1) {
  206. // uni.showToast({
  207. // title: '请选择参考风格',
  208. // icon: 'none'
  209. // })
  210. // return
  211. // }
  212. let style = '';
  213. if (this.selectedStyle !== -1) {
  214. style = this.styleList[this.selectedStyle].name
  215. }
  216. let that = this
  217. uni.request({
  218. url: this.$apiHost + '/WorkAI/creatorLG',
  219. data: {
  220. uuid: getApp().globalData.uuid,
  221. description: this.description,
  222. action: this.action,
  223. environment: this.environment,
  224. subject: this.image,
  225. style: style
  226. },
  227. method: 'POST',
  228. header: {
  229. 'Content-Type': 'application/x-www-form-urlencoded',
  230. 'sign': getApp().globalData.headerSign
  231. },
  232. dataType: 'json',
  233. success: (res) => {
  234. console.log("生成结果:", res.data);
  235. uni.showToast({
  236. title: res.data.str || '请求成功',
  237. icon: 'none'
  238. });
  239. if (res.data.success == "yes") {
  240. // TODO: 处理生成成功后的逻辑
  241. setTimeout(function() {
  242. // that.checkQueueStatus()
  243. uni.navigateBack()
  244. }, 500);
  245. }
  246. },
  247. fail: (err) => {
  248. console.log('生成失败:', err);
  249. uni.showToast({
  250. title: '生成请求失败',
  251. icon: 'none'
  252. });
  253. }
  254. })
  255. }
  256. }
  257. }
  258. </script>
  259. <style lang="scss">
  260. @import './makeImgDetail.scss';
  261. </style>