123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- <template>
- <view class="container">
- <navBar title="绘本生成" :back="true" color="#333333" background="#FFFFFF" />
- <loadingPage v-if="showLoadingPage" />
- <view class="topBox" :style="{'background-image':`url(${picBase+'hb_bg.png'})`}">
- <view class="left">
- <!-- <image :src="picBase+'hb_ai.png'" mode="heightFix" class="aiIcon" @click="upload"></image> -->
- <image src="@/static/other/ai_logo.png" mode="heightFix" class="aiIcon" @click="upload"></image>
- </view>
- <view class="right">
- <!-- <view class="label1">
- 纯AI制作
- </view> -->
- <!-- <image :src="picBase+'hb_txt.png'" mode="heightFix" class="label1" @click="upload"></image> -->
- <image src="@/static/other/dthzz.png" mode="heightFix" class="label1" @click="upload"></image>
- <view class="label2">
- 创作独一无二的绘本
- </view>
- </view>
- </view>
- <view class="mainBox">
- <view class="titleBox">
- <image :src="picBase+'s_star.png'" mode="heightFix" class="starIcon" @click="upload"></image>
- 上传一张故事主角的照片
- </view>
- <view class="uploadBox">
- <view class="tipBox">
- <image :src="picBase+'hb_tips.png'" mode="heightFix" class="tipIcon" @click="upload"></image>
- 绘本内容会根据您所上传的照片进行创作
- </view>
- <view class="selBox">
- <u-upload :fileList="fileList1" @afterRead="afterRead" @delete="deletePic" name="1" multiple
- :maxCount="1">
- <view class="myUpArea">
- <image :src="picBase+'upCamera.png'" mode="heightFix" class="upIcon">
- </image>
- 上传图片
- </view>
- </u-upload>
- </view>
- </view>
- </view>
- <view class="parmasBox">
- <view class="titleBox">
- <image :src="picBase+'s_star.png'" mode="heightFix" class="starIcon" @click="upload"></image>
- 故事主角信息
- </view>
- <view class="inputBox">
- <view class="selAndTileBox">
- <view class="nickname">
- <input type="text" class="nackI" v-model="formData.nickName" placeholder="请输入昵称" />
- <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
- </image>
- </view>
- <view class="selBtn" @click="show5=true">
- 选择主角
- </view>
- </view>
- <view class="otherBox">
- <view class="item" @click="show=true">
- <input type="text" class="nackI" disabled v-model="formData.sex" placeholder="选择性别" />
- <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
- </image>
- </view>
- <view class="item" @click="show2=true">
- <input type="text" class="nackI" disabled v-model="formData.ageName" placeholder="选择年龄" />
- <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
- </image>
- </view>
- <view class="item" @click="show3=true">
- <input type="text" class="nackI" disabled v-model="formData.star" placeholder="选择星座" />
- <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
- </image>
- </view>
- <view class="item" @click="show4=true">
- <input type="text" class="nackI" disabled v-model="formData.className" placeholder="选择年级" />
- <image :src="picBase+'arrR2.png'" mode="heightFix" class="arrIcon">
- </image>
- </view>
- </view>
- </view>
- </view>
- <view class="pos">
- </view>
- <view class="btnBox">
- <view class="left" @click="toKefu">
- <image :src="picBase+'kefu.png'" mode="heightFix" class="kfIcon">
- </image>
- 客服
- </view>
- <view class="right" @click="gen">
- <view class="top">
- 立即生成
- </view>
- <view class="bot">
- 绘本生成剩余次数:{{diamond}}次
- </view>
- </view>
- </view>
- <u-picker :show="show" class="my-picker" title="性别选择" aColor="#007AFF" :columns="columns" confirmColor="#007AFF"
- @confirm="confirm1" @cancel="show=false"></u-picker>
- <u-picker :show="show2" title="年龄选择" keyName="label" aColor="#007AFF" :columns="columns2" confirmColor="#007AFF"
- @confirm="confirm2" @cancel="show2=false"></u-picker>
- <u-picker :show="show3" title="星座选择" aColor="#007AFF" :columns="columns3" confirmColor="#007AFF"
- @confirm="confirm3" @cancel="show3=false"></u-picker>
- <u-picker :show="show4" title="班级选择" aColor="#007AFF" :columns="columns4" confirmColor="#007AFF"
- @confirm="confirm4" @cancel="show4=false"></u-picker>
- <u-picker keyName="name" :show="show5" title="选择主角" aColor="#007AFF" :columns="columns5" confirmColor="#007AFF"
- @confirm="confirm5" @cancel="show5=false"></u-picker>
- </view>
- </template>
- <script>
- // import navBar from '@/components/navBar/index.vue'
- import uploadUrl from '@/common/config.js'
- import {
- getUserInfo,
- getRoleparmas,
- postTask
- } from '@/api/index/index.js'
- export default {
- // components: {
- // navBar
- // },
- data() {
- return {
- showLoadingPage: true,
- // roleList:[],
- picBase: this.$picBase2,
- fileList1: [],
- formData: {
- nickName: '',
- sex: '',
- ageName: '',
- age: -1,
- star: '',
- className: '',
- class: -1
- },
- show: false,
- columns: [
- ['男孩', '女孩']
- ],
- show2: false,
- columns2: [
- [
- '1岁',
- '2岁',
- '3岁',
- '4岁',
- '5岁',
- '6岁',
- '7岁',
- '8岁',
- '9岁',
- '10岁',
- '11岁',
- '12岁',
- '13岁',
- '14岁',
- '15岁',
- '16岁',
- ]
- ],
- show3: false,
- columns3: [
- ['白羊座', '金牛座', '双子座 ', '巨蟹座', '狮子座', '处女座', '天秤座', '天蝎座', '射手座', '摩羯座', '水瓶座', '双鱼座']
- ],
- show4: false,
- columns4: [
- ['幼儿园', '一年级', '二年级', '三年级', '四年级', '五年级', '六年级']
- ],
- show5: false,
- columns5: [
- ],
- roleId: -1,
- diamond: 0,
- oldSeledRole: null,
- // showLoadingPage: true
- }
- },
- onLoad() {
- setTimeout(() => {
- this.showLoadingPage = false
- }, 1000)
- this.getUserInfo()
- this.getRoleparmas()
- // this.reShow2()
- },
- onShow() {
- // if (getApp().refreshRole) {
- // this.getRoleparmas()
- // getApp().refreshRole = null
- // }
- },
- methods: {
- reShow2() {
- // 回显方式2
- // this.formData.nickName = res1.data.data[i].name
- this.formData.sex = this.columns[0][0]
- this.formData.age = 1
- this.formData.ageName = '1岁'
- this.formData.star = this.columns3[0][0]
- this.formData.className = this.columns4[0][0]
- this.formData.class = 0
- },
- async getUserInfo() {
- let res1 = await getUserInfo()
- console.log('用户信息返回值--------', res1);
- if (res1.code == 0) {
- uni.setStorageSync('userInfo', res1.data)
- this.diamond = res1.data.diamond
- } else {
- this.$toast(res1.message)
- }
- },
- toKefu() {
- uni.navigateTo({
- url: '/pages/my/kefu/index'
- })
- },
- async gen() {
- if (this.diamond <= 0) {
- wx.showModal({
- title: '提示',
- content: '您的剩余次数为' + this.diamond + ',请充值!',
- confirmText: '去充值',
- confirmColor: "#017EFF",
- cancelText: '稍后',
- success(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- let res = wx.getSystemInfoSync();
- if (res.platform == 'ios') {
- return wx.showModal({
- title: '提示',
- content: '【由于相关规范,iOS功能暂不可用】',
- success(res) {
- if (res.confirm) {
- console.log('用户点击确定')
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- }
- uni.navigateTo({
- url: '/pages/my/charge/index?from=gen'
- })
- } else if (res.cancel) {
- console.log('用户点击取消')
- }
- }
- })
- return
- }
- if (this.fileList1.length == 0) {
- return this.$toast('请上传图片')
- }
- if (this.fileList1[0].status == 'uploading') {
- return this.$toast('请等待图片上传完成')
- }
- // return console.log('picItem----------------', this.fileList1[0].status);
- if (!this.formData.nickName) {
- return this.$toast('请输入昵称')
- }
- if (!this.formData.sex) {
- return this.$toast('请选择性别')
- }
- if (this.formData.age == -1) {
- return this.$toast('请选择年龄')
- }
- if (!this.formData.star) {
- return this.$toast('请选择星座')
- }
- if (this.formData.class == -1) {
- return this.$toast('请选择班级')
- }
- let p = {}
- // 判断用户是否修改了角色信息
- if (this.oldSeledRole) {
- if (this.oldSeledRole.name != this.formData.nickName || this.oldSeledRole.star != this.formData
- .star || this.oldSeledRole.sex != this.formData
- .sex || this.oldSeledRole.age != this.formData.age || this.oldSeledRole.level != this.formData
- .class) {
- console.log('用户修改了预置角色------------------');
- this.roleId = -1
- }
- }
- console.log('用户wei修改了预置角色------------------');
- if (this.roleId != -1) {
- p = {
- roleId: this.roleId,
- image: this.fileList1[0].url
- }
- } else {
- p = {
- image: this.fileList1[0].url,
- name: this.formData.nickName,
- sex: this.formData.sex,
- age: this.formData.age,
- star: this.formData.star,
- level: this.formData.class,
- }
- }
- // return console.log('p----------------', p);
- let res1 = await postTask(p)
- console.log('生成任务提交返回值--------2', res1);
- if (res1.code == 0) {
- this.$toast('任务提交成功', 'success')
- setTimeout(() => {
- uni.redirectTo({
- url: '/pages/index/genRes/index?taskId=' + res1.data.id
- })
- }, 1500)
- } else {
- this.$toast(res1.message)
- }
- },
- async getRoleparmas() {
- let res1 = await getRoleparmas()
- console.log('角色列表返回值--------2', res1);
- if (res1.code == 0) {
- // res1.data.data = []
- if (res1.data.data.length != 0) {
- res1.data.data = res1.data.data.reverse()
- // 用于比对用户是否修改主角内容
- // let i=res1.data.data.length-1
- this.columns5[0] = res1.data.data
- // 回显方式1
- let i = 0
- this.oldSeledRole = res1.data.data[i]
- this.roleId = res1.data.data[i].id
- this.formData.nickName = res1.data.data[i].name
- this.formData.sex = res1.data.data[i].sex
- this.formData.age = res1.data.data[i].age
- this.formData.ageName = this.columns2[0][Number(res1.data.data[i].age) - 1]
- this.formData.star = res1.data.data[i].star
- this.formData.className = this.columns4[0][Number(res1.data.data[i].level)]
- this.formData.class = res1.data.data[i].level
- } else {
- this.reShow2()
- this.columns5[0] = ['暂无']
- }
- // this.chargeList=[]
- } else {
- this.$toast(res1.message)
- }
- },
- confirm1(e) {
- console.log('e', e);
- this.formData.sex = e.value[0]
- this.show = false
- },
- confirm2(e) {
- console.log('e', e);
- this.formData.ageName = this.columns2[0][e.indexs[0]]
- this.formData.age = e.indexs[0] + 1
- this.show2 = false
- },
- confirm3(e) {
- console.log('e', e);
- this.formData.star = e.value[0]
- this.show3 = false
- },
- confirm4(e) {
- console.log('e', e);
- // this.formData.class = e.value[0]
- this.formData.class = e.indexs[0]
- this.formData.className = e.value[0]
- console.log('confirm4--level', this.formData.class);
- this.show4 = false
- },
- confirm5(e) {
- if (e.value[0] == '暂无') {
- this.show5 = false
- return
- }
- this.oldSeledRole = e.value[0]
- console.log('e-----5', e.indexs[0], e.value[0]);
- this.formData.class = e.value[0].level
- this.formData.className = this.columns4[0][Number(e.value[0].level)]
- this.formData.nickName = e.value[0].name
- this.formData.sex = e.value[0].sex
- this.formData.star = e.value[0].star
- this.formData.age = e.value[0].age
- this.formData.ageName = this.columns2[0][Number(e.value[0].age - 1)]
- this.roleId = e.value[0].id
- this.show5 = false
- },
- // 删除图片
- deletePic(event) {
- this[`fileList${event.name}`].splice(event.index, 1)
- },
- // 新增图片
- async afterRead(event) {
- // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
- let lists = [].concat(event.file)
- let fileListLen = this[`fileList${event.name}`].length
- lists.map((item) => {
- this[`fileList${event.name}`].push({
- ...item,
- status: 'uploading',
- message: '上传中'
- })
- })
- for (let i = 0; i < lists.length; i++) {
- const result = await this.uploadFilePromise(lists[i].url)
- let item = this[`fileList${event.name}`][fileListLen]
- this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
- status: 'success',
- message: '',
- url: result
- }))
- fileListLen++
- }
- },
- uploadFilePromise(url) {
- return new Promise((resolve, reject) => {
- let a = uni.uploadFile({
- // url: 'http://192.168.2.21:7001/upload', // 仅为示例,非真实的接口地址
- url: uploadUrl.baseUrl + '/api/avatar/upload', // 仅为示例,非真实的接口地址
- filePath: url,
- name: 'file',
- header: {
- 'Content-Type': 'multipart/form-data',
- 'Authorization': uni.getStorageSync('token')
- },
- formData: {
- user: 'test',
- 'tag': 'lamp',
- },
- success: (res) => {
- console.log('uploadFilePromise返回值', res);
- setTimeout(() => {
- resolve(JSON.parse(res.data).data.url)
- }, 1000)
- }
- });
- })
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- @import "./index.scss";
- </style>
|