index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506
  1. <template>
  2. <view class="container">
  3. <navBar title="绘本生成" :back="true" color="#333333" background="#FFFFFF" />
  4. <loadingPage v-if="showLoadingPage" />
  5. <view class="topBox" :style="{'background-image':`url(${picBase+'hb_bg.png'})`}">
  6. <view class="left">
  7. <!-- <image :src="picBase+'hb_ai.png'" mode="heightFix" class="aiIcon" @click="upload"></image> -->
  8. <image src="@/static/other/ai_logo.png" mode="heightFix" class="aiIcon" @click="upload"></image>
  9. </view>
  10. <view class="right">
  11. <!-- <view class="label1">
  12. 纯AI制作
  13. </view> -->
  14. <!-- <image :src="picBase+'hb_txt.png'" mode="heightFix" class="label1" @click="upload"></image> -->
  15. <image src="@/static/other/dthzz.png" mode="heightFix" class="label1" @click="upload"></image>
  16. <view class="label2">
  17. 创作独一无二的绘本
  18. </view>
  19. </view>
  20. </view>
  21. <view class="mainBox">
  22. <view class="titleBox">
  23. <image :src="picBase+'s_star.png'" mode="heightFix" class="starIcon" @click="upload"></image>
  24. 上传一张故事主角的照片
  25. </view>
  26. <view class="uploadBox">
  27. <view class="tipBox">
  28. <image :src="picBase+'hb_tips.png'" mode="heightFix" class="tipIcon" @click="upload"></image>
  29. 绘本内容会根据您所上传的照片进行创作
  30. </view>
  31. <view class="selBox">
  32. <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
  33. :maxCount="1">
  34. <view class="myUpArea">
  35. <image :src="picBase+'upCamera.png'" mode="heightFix" class="upIcon">
  36. </image>
  37. 上传图片
  38. </view>
  39. </u-upload>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="parmasBox">
  44. <view class="titleBox">
  45. <image :src="picBase+'s_star.png'" mode="heightFix" class="starIcon" @click="upload"></image>
  46. 故事主角信息
  47. </view>
  48. <view class="inputBox">
  49. <view class="selAndTileBox">
  50. <view class="nickname">
  51. <input type="text" class="nackI" v-model="formData.nickName" placeholder="请输入昵称" />
  52. <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
  53. </image>
  54. </view>
  55. <view class="selBtn" @click="show5=true">
  56. 选择主角
  57. </view>
  58. </view>
  59. <view class="otherBox">
  60. <view class="item" @click="show=true">
  61. <input type="text" class="nackI" disabled v-model="formData.sex" placeholder="选择性别" />
  62. <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
  63. </image>
  64. </view>
  65. <view class="item" @click="show2=true">
  66. <input type="text" class="nackI" disabled v-model="formData.ageName" placeholder="选择年龄" />
  67. <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
  68. </image>
  69. </view>
  70. <view class="item" @click="show3=true">
  71. <input type="text" class="nackI" disabled v-model="formData.star" placeholder="选择星座" />
  72. <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
  73. </image>
  74. </view>
  75. <view class="item" @click="show4=true">
  76. <input type="text" class="nackI" disabled v-model="formData.className" placeholder="选择年级" />
  77. <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
  78. </image>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <view class="pos">
  84. </view>
  85. <view class="btnBox">
  86. <view class="left" @click="toKefu">
  87. <image :src="picBase+'kefu.png'" mode="heightFix" class="kfIcon">
  88. </image>
  89. 客服
  90. </view>
  91. <view class="right" @click="gen">
  92. <view class="top">
  93. 立即生成
  94. </view>
  95. <view class="bot">
  96. 绘本生成剩余次数:{{diamond}}次
  97. </view>
  98. </view>
  99. </view>
  100. <u-picker :show="show" class="my-picker" title="性别选择" aColor="#007AFF" :columns="columns" confirmColor="#007AFF"
  101. @confirm="confirm1" @cancel="show=false"></u-picker>
  102. <u-picker :show="show2" title="年龄选择" keyName="label" aColor="#007AFF" :columns="columns2" confirmColor="#007AFF"
  103. @confirm="confirm2" @cancel="show2=false"></u-picker>
  104. <u-picker :show="show3" title="星座选择" aColor="#007AFF" :columns="columns3" confirmColor="#007AFF"
  105. @confirm="confirm3" @cancel="show3=false"></u-picker>
  106. <u-picker :show="show4" title="班级选择" aColor="#007AFF" :columns="columns4" confirmColor="#007AFF"
  107. @confirm="confirm4" @cancel="show4=false"></u-picker>
  108. <u-picker keyName="name" :show="show5" title="选择主角" aColor="#007AFF" :columns="columns5" confirmColor="#007AFF"
  109. @confirm="confirm5" @cancel="show5=false"></u-picker>
  110. </view>
  111. </template>
  112. <script>
  113. // import navBar from '@/components/navBar/index.vue'
  114. import uploadUrl from '@/common/config.js'
  115. import {
  116. getUserInfo,
  117. getRoleparmas,
  118. postTask
  119. } from '@/api/index/index.js'
  120. export default {
  121. // components: {
  122. // navBar
  123. // },
  124. data() {
  125. return {
  126. showLoadingPage: true,
  127. // roleList:[],
  128. picBase: this.$picBase2,
  129. fileList1: [],
  130. formData: {
  131. nickName: '',
  132. sex: '',
  133. ageName: '',
  134. age: -1,
  135. star: '',
  136. className: '',
  137. class: -1
  138. },
  139. show: false,
  140. columns: [
  141. ['男孩', '女孩']
  142. ],
  143. show2: false,
  144. columns2: [
  145. [
  146. '1岁',
  147. '2岁',
  148. '3岁',
  149. '4岁',
  150. '5岁',
  151. '6岁',
  152. '7岁',
  153. '8岁',
  154. '9岁',
  155. '10岁',
  156. '11岁',
  157. '12岁',
  158. '13岁',
  159. '14岁',
  160. '15岁',
  161. '16岁',
  162. ]
  163. ],
  164. show3: false,
  165. columns3: [
  166. ['白羊座', '金牛座', '双子座 ', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座']
  167. ],
  168. show4: false,
  169. columns4: [
  170. ['幼儿园', '一年级', '二年级', '三年级', '四年级', '五年级', '六年级']
  171. ],
  172. show5: false,
  173. columns5: [
  174. ],
  175. roleId: -1,
  176. diamond: 0,
  177. oldSeledRole: null,
  178. // showLoadingPage: true
  179. }
  180. },
  181. onLoad() {
  182. setTimeout(() => {
  183. this.showLoadingPage = false
  184. }, 1000)
  185. this.getUserInfo()
  186. this.getRoleparmas()
  187. // this.reShow2()
  188. },
  189. onShow() {
  190. // if (getApp().refreshRole) {
  191. // this.getRoleparmas()
  192. // getApp().refreshRole = null
  193. // }
  194. },
  195. methods: {
  196. reShow2() {
  197. // 回显方式2
  198. // this.formData.nickName = res1.data.data[i].name
  199. this.formData.sex = this.columns[0][0]
  200. this.formData.age = 1
  201. this.formData.ageName = '1岁'
  202. this.formData.star = this.columns3[0][0]
  203. this.formData.className = this.columns4[0][0]
  204. this.formData.class = 0
  205. },
  206. async getUserInfo() {
  207. let res1 = await getUserInfo()
  208. console.log('用户信息返回值--------', res1);
  209. if (res1.code == 0) {
  210. uni.setStorageSync('userInfo', res1.data)
  211. this.diamond = res1.data.diamond
  212. } else {
  213. this.$toast(res1.message)
  214. }
  215. },
  216. toKefu() {
  217. uni.navigateTo({
  218. url: '/pages/my/kefu/index'
  219. })
  220. },
  221. async gen() {
  222. if (this.diamond <= 0) {
  223. wx.showModal({
  224. title: '提示',
  225. content: '您的剩余次数为' + this.diamond + ',请充值!',
  226. confirmText: '去充值',
  227. confirmColor: "#017EFF",
  228. cancelText: '稍后',
  229. success(res) {
  230. if (res.confirm) {
  231. console.log('用户点击确定')
  232. let res = wx.getSystemInfoSync();
  233. if (res.platform == 'ios') {
  234. return wx.showModal({
  235. title: '提示',
  236. content: '【由于相关规范,iOS功能暂不可用】',
  237. success(res) {
  238. if (res.confirm) {
  239. console.log('用户点击确定')
  240. } else if (res.cancel) {
  241. console.log('用户点击取消')
  242. }
  243. }
  244. })
  245. }
  246. uni.navigateTo({
  247. url: '/pages/my/charge/index?from=gen'
  248. })
  249. } else if (res.cancel) {
  250. console.log('用户点击取消')
  251. }
  252. }
  253. })
  254. return
  255. }
  256. if (this.fileList1.length == 0) {
  257. return this.$toast('请上传图片')
  258. }
  259. if (this.fileList1[0].status == 'uploading') {
  260. return this.$toast('请等待图片上传完成')
  261. }
  262. // return console.log('picItem----------------', this.fileList1[0].status);
  263. if (!this.formData.nickName) {
  264. return this.$toast('请输入昵称')
  265. }
  266. if (!this.formData.sex) {
  267. return this.$toast('请选择性别')
  268. }
  269. if (this.formData.age == -1) {
  270. return this.$toast('请选择年龄')
  271. }
  272. if (!this.formData.star) {
  273. return this.$toast('请选择星座')
  274. }
  275. if (this.formData.class == -1) {
  276. return this.$toast('请选择班级')
  277. }
  278. let p = {}
  279. // 判断用户是否修改了角色信息
  280. if (this.oldSeledRole) {
  281. if (this.oldSeledRole.name != this.formData.nickName || this.oldSeledRole.star != this.formData
  282. .star || this.oldSeledRole.sex != this.formData
  283. .sex || this.oldSeledRole.age != this.formData.age || this.oldSeledRole.level != this.formData
  284. .class) {
  285. console.log('用户修改了预置角色------------------');
  286. this.roleId = -1
  287. }
  288. }
  289. console.log('用户wei修改了预置角色------------------');
  290. if (this.roleId != -1) {
  291. p = {
  292. roleId: this.roleId,
  293. image: this.fileList1[0].url
  294. }
  295. } else {
  296. p = {
  297. image: this.fileList1[0].url,
  298. name: this.formData.nickName,
  299. sex: this.formData.sex,
  300. age: this.formData.age,
  301. star: this.formData.star,
  302. level: this.formData.class,
  303. }
  304. }
  305. // return console.log('p----------------', p);
  306. let res1 = await postTask(p)
  307. console.log('生成任务提交返回值--------2', res1);
  308. if (res1.code == 0) {
  309. this.$toast('任务提交成功', 'success')
  310. setTimeout(() => {
  311. uni.redirectTo({
  312. url: '/pages/index/genRes/index?taskId=' + res1.data.id
  313. })
  314. }, 1500)
  315. } else {
  316. this.$toast(res1.message)
  317. }
  318. },
  319. async getRoleparmas() {
  320. let res1 = await getRoleparmas()
  321. console.log('角色列表返回值--------2', res1);
  322. if (res1.code == 0) {
  323. // res1.data.data = []
  324. if (res1.data.data.length != 0) {
  325. res1.data.data = res1.data.data.reverse()
  326. // 用于比对用户是否修改主角内容
  327. // let i=res1.data.data.length-1
  328. this.columns5[0] = res1.data.data
  329. // 回显方式1
  330. let i = 0
  331. this.oldSeledRole = res1.data.data[i]
  332. this.roleId = res1.data.data[i].id
  333. this.formData.nickName = res1.data.data[i].name
  334. this.formData.sex = res1.data.data[i].sex
  335. this.formData.age = res1.data.data[i].age
  336. this.formData.ageName = this.columns2[0][Number(res1.data.data[i].age) - 1]
  337. this.formData.star = res1.data.data[i].star
  338. this.formData.className = this.columns4[0][Number(res1.data.data[i].level)]
  339. this.formData.class = res1.data.data[i].level
  340. } else {
  341. this.reShow2()
  342. this.columns5[0] = ['暂无']
  343. }
  344. // this.chargeList=[]
  345. } else {
  346. this.$toast(res1.message)
  347. }
  348. },
  349. confirm1(e) {
  350. console.log('e', e);
  351. this.formData.sex = e.value[0]
  352. this.show = false
  353. },
  354. confirm2(e) {
  355. console.log('e', e);
  356. this.formData.ageName = this.columns2[0][e.indexs[0]]
  357. this.formData.age = e.indexs[0] + 1
  358. this.show2 = false
  359. },
  360. confirm3(e) {
  361. console.log('e', e);
  362. this.formData.star = e.value[0]
  363. this.show3 = false
  364. },
  365. confirm4(e) {
  366. console.log('e', e);
  367. // this.formData.class = e.value[0]
  368. this.formData.class = e.indexs[0]
  369. this.formData.className = e.value[0]
  370. console.log('confirm4--level', this.formData.class);
  371. this.show4 = false
  372. },
  373. confirm5(e) {
  374. if (e.value[0] == '暂无') {
  375. this.show5 = false
  376. return
  377. }
  378. this.oldSeledRole = e.value[0]
  379. console.log('e-----5', e.indexs[0], e.value[0]);
  380. this.formData.class = e.value[0].level
  381. this.formData.className = this.columns4[0][Number(e.value[0].level)]
  382. this.formData.nickName = e.value[0].name
  383. this.formData.sex = e.value[0].sex
  384. this.formData.star = e.value[0].star
  385. this.formData.age = e.value[0].age
  386. this.formData.ageName = this.columns2[0][Number(e.value[0].age - 1)]
  387. this.roleId = e.value[0].id
  388. this.show5 = false
  389. },
  390. // 删除图片
  391. deletePic(event) {
  392. this[`fileList${event.name}`].splice(event.index, 1)
  393. },
  394. // 新增图片
  395. async afterRead(event) {
  396. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  397. let lists = [].concat(event.file)
  398. let fileListLen = this[`fileList${event.name}`].length
  399. lists.map((item) => {
  400. this[`fileList${event.name}`].push({
  401. ...item,
  402. status: 'uploading',
  403. message: '上传中'
  404. })
  405. })
  406. for (let i = 0; i < lists.length; i++) {
  407. const result = await this.uploadFilePromise(lists[i].url)
  408. let item = this[`fileList${event.name}`][fileListLen]
  409. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  410. status: 'success',
  411. message: '',
  412. url: result
  413. }))
  414. fileListLen++
  415. }
  416. },
  417. uploadFilePromise(url) {
  418. return new Promise((resolve, reject) => {
  419. let a = uni.uploadFile({
  420. // url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
  421. url: uploadUrl.baseUrl + '/api/avatar/upload', // 仅为示例,非真实的接口地址
  422. filePath: url,
  423. name: 'file',
  424. header: {
  425. 'Content-Type': 'multipart/form-data',
  426. 'Authorization': uni.getStorageSync('token')
  427. },
  428. formData: {
  429. user: 'test',
  430. 'tag': 'lamp',
  431. },
  432. success: (res) => {
  433. console.log('uploadFilePromise返回值', res);
  434. setTimeout(() => {
  435. resolve(JSON.parse(res.data).data.url)
  436. }, 1000)
  437. }
  438. });
  439. })
  440. },
  441. }
  442. }
  443. </script>
  444. <style lang="scss" scoped>
  445. @import "./index.scss";
  446. </style>