addRole.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title='创建角色' bgColor="transparent"></cus-header>
  4. <div class="box">
  5. <div class="title adfac">角色形象<span>*</span></div>
  6. <div class="upload">
  7. <div class="sc">
  8. <u-upload width="188rpx" height="188rpx"
  9. :fileList="fileList"
  10. @afterRead="afterRead"
  11. @delete="deletePic"
  12. :maxCount="1"
  13. >
  14. <div class="imgs">
  15. <image class="img1" src="http://106.54.209.120:8188/static/role_upload.png"></image>
  16. <image class="img2" src="http://106.54.209.120:8188/static/upload_add.png"></image>
  17. </div>
  18. </u-upload>
  19. </div>
  20. <div class="text">上传角色形象</div>
  21. </div>
  22. </div>
  23. <div class="box adfacjb">
  24. <div class="title">角色昵称<span>*</span></div>
  25. <input type="text" placeholder="请输入角色昵称" placeholder-class="ph">
  26. </div>
  27. <div class="box adfacjb" @tap="selectModel">
  28. <div class="title">角色模板<span>*</span></div>
  29. <div class="right adfac">
  30. <div class="mtext" :class="{'active':modelText!=='请选择角色模版'}">{{modelText}}</div>
  31. <image src="http://106.54.209.120:8188/static/arrow_right.png"></image>
  32. </div>
  33. </div>
  34. <div class="box">
  35. <div class="top adfacjb">
  36. <div class="title">设备描述</div>
  37. <div class="tip">回显不可编辑</div>
  38. </div>
  39. <div class="desc">{{''}}</div>
  40. </div>
  41. <div class="box adfacjb">
  42. <div class="title">音色<span>*</span></div>
  43. <div class="right adfac">
  44. <div class="mtext" :class="{'active':voiceText!=='请选择音色'}">{{voiceText}}</div>
  45. <image src="http://106.54.209.120:8188/static/arrow_right.png"></image>
  46. </div>
  47. </div>
  48. <div class="zt_btn">创建角色</div>
  49. <u-picker :itemHeight="88" title="角色音色" :show="show" :columns="voiceList" keyName="name"
  50. @cancel="show=false" @confirm="confirm" :immediateChange="true" style="height: 500rpx;">
  51. </u-picker>
  52. </view>
  53. </template>
  54. <script>
  55. const baseApi = require('@/http/baseApi.js')
  56. export default {
  57. data(){
  58. return {
  59. modelText:'请选择角色模版',
  60. voiceText:'请选择音色',
  61. fileList:[],
  62. show:false,
  63. voiceList:[],
  64. modelMap:new Map(),
  65. agentDto:{
  66. }
  67. }
  68. },
  69. async onLoad() {
  70. await this.getAgentModelList()
  71. this.getModelVoiceList()
  72. },
  73. methods:{
  74. // 删除图片
  75. deletePic(event) {
  76. this.fileList.splice(event.index, 1);
  77. },
  78. // 新增图片
  79. async afterRead(event) {
  80. // 当设置 multiple 为 true 时, file 为数组格式,否则为对象格式
  81. let lists = [].concat(event.file);
  82. let fileListLen = this.fileList.length;
  83. lists.map((item) => {
  84. this.fileList.push({
  85. ...item,
  86. status: "uploading",
  87. message: "上传中",
  88. });
  89. });
  90. for (let i = 0; i < lists.length; i++) {
  91. const result = await this.uploadFilePromise(lists[i].url);
  92. let item = this.fileList[fileListLen];
  93. this.fileList.splice(
  94. fileListLen,
  95. 1,
  96. Object.assign(item, {
  97. status: "success",
  98. message: "",
  99. url: result,
  100. })
  101. );
  102. fileListLen++;
  103. }
  104. },
  105. uploadFilePromise(url) {
  106. return new Promise((resolve, reject) => {
  107. let a = uni.uploadFile({
  108. url: baseApi.BaseApi + '/uploadFile',
  109. filePath: url,
  110. name: "file",
  111. success: (res) => {
  112. let data = JSON.parse(res.data);
  113. if(data){
  114. if(data.code!==0) return
  115. setTimeout(() => {
  116. resolve(data.data);
  117. }, 1000);
  118. }
  119. },
  120. });
  121. });
  122. },
  123. changeModel(item,index){
  124. this.midx = index;
  125. this.agentDto = this.modelMap.get(item.agentName);
  126. this.getModelVoiceList()
  127. },
  128. selectModel(){
  129. uni.navigateTo({
  130. url:'/pagesRole/roleModel',
  131. events:{
  132. selectRoleModel:data=>{
  133. console.log(data,'data');
  134. }
  135. }
  136. })
  137. },
  138. getAgentModelList(){
  139. return new Promise((resolve,reject)=>{
  140. this.$api.get('/agent/template').then(res=>{
  141. if(res.data.code!==0) return this.$showToast(res.data.msg)
  142. this.list = res.data.data;
  143. if(this.list.length){
  144. this.agentDto = {...this.agentDto,...this.list[0]}
  145. let map = new Map();
  146. this.list.forEach(l=>{
  147. map.set(l.agentName,l)
  148. })
  149. this.modelMap = map;
  150. }
  151. resolve();
  152. })
  153. })
  154. },
  155. getModelVoiceList(){
  156. this.$api.get(`/models/${this.agentDto.ttsModelId}/voices`).then(res=>{
  157. if(res.data.code!==0) return this.$showToast(res.data.msg)
  158. this.voiceList = [res.data.data];
  159. this.voiceText = res.data.data.find(v=>v.id===this.agentDto.ttsVoiceId)?.name||'';
  160. })
  161. },
  162. confirm(e){
  163. this.show = false;
  164. this.agentDto.ttsVoiceId = e.value[0].id;
  165. this.voiceText = e.value[0].name;
  166. },
  167. comfirmSure(){
  168. let dto = JSON.parse(JSON.stringify(this.agentDto));
  169. this.$api.post('/agent',dto).then(res=>{
  170. if(res.data.code!==0) return this.$showToast(res.data.msg)
  171. this.$showToast('创建成功');
  172. setTimeout(()=>{
  173. uni.reLaunch({
  174. url:'/pages/home'
  175. })
  176. },1500)
  177. })
  178. },
  179. }
  180. }
  181. </script>
  182. <style scoped lang="less">
  183. .ph{
  184. font-family: PingFangSC, PingFang SC;
  185. font-weight: 400;
  186. font-size: 28rpx;
  187. color: #A6A6A6;
  188. line-height: 40rpx;
  189. text-align: right;
  190. }
  191. .page{
  192. background: #F7F6F9;
  193. padding: 0 30rpx 30rpx;
  194. .box{
  195. background: #FFFFFF;
  196. border-radius: 24rpx;
  197. margin-top: 20rpx;
  198. width: 100%;
  199. padding: 40rpx 30rpx;
  200. box-sizing: border-box;
  201. .title{
  202. font-family: PingFang-SC, PingFang-SC;
  203. font-weight: bold;
  204. font-size: 30rpx;
  205. color: #111111;
  206. line-height: 32rpx;
  207. span{
  208. font-size: 32rpx;
  209. color: #F31616;
  210. }
  211. }
  212. .upload{
  213. margin-top: 12rpx;
  214. display: flex;
  215. flex-direction: column;
  216. align-items: center;
  217. .sc{
  218. width: 188rpx;
  219. height: 188rpx;
  220. }
  221. .text{
  222. font-family: PingFangSC, PingFang SC;
  223. font-weight: 400;
  224. font-size: 26rpx;
  225. color: #A6A6A6;
  226. line-height: 37rpx;
  227. text-align: center;
  228. margin-top: 8rpx;
  229. }
  230. }
  231. .right{
  232. .mtext{
  233. font-family: PingFangSC, PingFang SC;
  234. font-weight: 400;
  235. font-size: 28rpx;
  236. color: #A6A6A6;
  237. line-height: 40rpx;
  238. text-align: right;
  239. &.active{
  240. color: #111111;
  241. }
  242. }
  243. image{
  244. width: 36rpx;
  245. height: 36rpx;
  246. margin-left: 10rpx;
  247. }
  248. }
  249. .desc{
  250. margin-top: 20rpx;
  251. min-height: 200rpx;
  252. }
  253. .tip{
  254. font-family: PingFangSC, PingFang SC;
  255. font-weight: 400;
  256. font-size: 28rpx;
  257. color: #A6A6A6;
  258. line-height: 40rpx;
  259. text-align: right;
  260. }
  261. .imgs{
  262. width: 188rpx;
  263. height: 188rpx;
  264. border-radius: 50%;
  265. position: relative;
  266. .img1{
  267. width: 188rpx;
  268. height: 188rpx;
  269. border-radius: 50%;
  270. position: absolute;
  271. z-index: 2;
  272. }
  273. .img2{
  274. width: 42rpx;
  275. height: 42rpx;
  276. position: absolute;
  277. right: 0;
  278. bottom: 0;
  279. z-index: 3;
  280. }
  281. }
  282. }
  283. .zt_btn{
  284. margin-top: 54rpx;
  285. }
  286. input{
  287. border: none;
  288. text-align: right;
  289. font-size: 28rpx;
  290. }
  291. }
  292. </style>