myStar.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <template>
  2. <view class="star-container">
  3. <PageHeader title="" class="PageHeader" v-if="state == 1">
  4. <template slot="center"> </template>
  5. </PageHeader>
  6. <!-- 星灵基因重组仓弹窗 -->
  7. <view class="gender-popup" v-if="state == 0">
  8. <NicknamePopup title="星灵基因重组仓" subtitle="" class="openContentPopUpWindow" ref="openContentPopUpWindow">
  9. <template slot="content">
  10. <uv-textarea v-model="noteContent" maxlength="200" count autoHeight
  11. placeholder="可描述你想要重新赋予Ta的形象、性别、性格、身份、兴趣爱好等(不会展示给其他人,仅你自己知道),示例:有一头波浪状的橙色头发,喜欢运动的阳光男孩..."></uv-textarea>
  12. <view class="btn-box" @tap="confirmGender">创建星灵</view>
  13. </template>
  14. </NicknamePopup>
  15. </view>
  16. <!-- 加载动画区域 -->
  17. <view class="loading-area" v-if="state == 2">
  18. <image src="../../static/me/loadAnimation.gif" mode="widthFix"></image>
  19. </view>
  20. <!-- 角色展示页面 -->
  21. <view class="character-page" v-else-if="state == 1">
  22. <view class="character-container">
  23. <image :src="starImg || 'https://e.zhichao.art/AI_images/b_3_92.png'" mode="widthFix"
  24. class="character-image">
  25. </image>
  26. </view>
  27. <view class="bottom-button" @tap="goToSetProfile"> 设置星灵简介 </view>
  28. </view>
  29. <!-- 表单页面 -->
  30. <view class="form-page" v-else-if="state == 4">
  31. <PageHeader title="设置星灵简介" class="PageHeader">
  32. <template slot="center"> </template>
  33. </PageHeader>
  34. <view class="reserveASeat"></view>
  35. <form @submit="submitForm">
  36. <view class="form-group">
  37. <view class="label">
  38. <text class="required">*</text>
  39. <text>昵称</text>
  40. </view>
  41. <input class="input" v-model="formData.nickname" placeholder="给星灵取个名字"
  42. :class="{ error: showError && !formData.nickname }" />
  43. </view>
  44. <view class="form-group">
  45. <view class="label">性别</view>
  46. <view class="gender-options">
  47. <view class="gender-option" :class="sex == 'male' ? 'selected' : ''">
  48. <view class="gender-icon male" @tap="selectGender('male')">
  49. <image src="../../static/me/wd_icon_nan.png" mode="aspectFit"></image>
  50. 男性
  51. </view>
  52. </view>
  53. <view class="gender-option" :class="sex == 'female' ? 'selected' : ''">
  54. <view class="gender-icon female" @tap="selectGender('female')">
  55. <image src="../../static/me/wd_icon_nv.png" mode="aspectFit"></image>
  56. 女性
  57. </view>
  58. </view>
  59. <view class="gender-option" :class="sex == 'other' ? 'selected' : ''">
  60. <view class="gender-icon other" @tap="selectGender('other')">
  61. <image src="../../static/me/wd_icon_qita.png" mode="aspectFit"></image>
  62. 其它
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="form-group">
  68. <view class="label">
  69. <text class="required">*</text>
  70. <text>人物简介</text>
  71. </view>
  72. <view class="textarea-container">
  73. <textarea class="textarea" v-model="formData.description"
  74. placeholder="填写这个角色的人物介绍,例如性格、身份、背景与历程..." :maxlength="500"
  75. :class="{ error: showError && !formData.description }" autoHeight />
  76. <text class="word-count">{{ formData.description.length }}/500</text>
  77. </view>
  78. </view>
  79. <view class="form-group">
  80. <view class="label">人物标签</view>
  81. <!-- <scroll-view class="tags-scroll" scroll-x="true" show-scrollbar="false">
  82. <view class="tags-container">
  83. <view class="tag" v-for="tag in predefinedTags" :key="tag">
  84. {{ tag }}
  85. </view>
  86. </view>
  87. </scroll-view> -->
  88. <view class="tags-container">
  89. <!-- <view class="tag" :class="{ active: tagSet.has(tag) }" v-for="tag in predefinedTags" :key="tag"
  90. @tap="switchTag(tag)">
  91. {{ tag }}
  92. </view> -->
  93. <uni-data-checkbox mode="tag" multiple v-model="selectTags"
  94. :localdata="predefinedTags"></uni-data-checkbox>
  95. </view>
  96. </view>
  97. </form>
  98. <view class="submit-button" @tap="submitStar"> 确定并提交 </view>
  99. </view>
  100. <!-- 角色信息展示页面 -->
  101. <view class="character-info" v-else-if="state == 5">
  102. <view class="custom-navbar">
  103. <view class="navbar-left" @click="goBack">
  104. <text class="fa fa-angle-left" style="color: #000;"></text>
  105. </view>
  106. <view class="navbar-right" @click="showShare = true">
  107. <text class="fa fa-ellipsis-h"></text>
  108. </view>
  109. </view>
  110. <view class="info-container">
  111. <!-- 角色立绘区域 -->
  112. <view class="character-portrait">
  113. <image :src="starInfo.image" mode="widthFix" class="portrait-image"></image>
  114. </view>
  115. <!-- 角色信息板块 -->
  116. <view class="info-section">
  117. <view class="character-name">
  118. {{ starInfo.name }}
  119. <image class="male" v-if="starInfo.sex == 0" src="../../static/me/wd_icon_nan.png"
  120. mode="aspectFit">
  121. </image>
  122. <image class="female" v-else-if="starInfo.sex == 1" src="../../static/me/wd_icon_nv.png"
  123. mode="aspectFit">
  124. </image>
  125. <image class="other" v-else src="../../static/me/wd_icon_qita.png" mode="aspectFit"></image>
  126. </view>
  127. <!-- <view class="section-title">关于Ta</view> -->
  128. <!-- 人物简介 -->
  129. <view class="description-box">
  130. <view class="description-title">
  131. <view>Ta的设定</view>
  132. <view v-if="false" class="edit-button">编辑<text class="fa fa-angle-right"
  133. style="color: #000;"></text></view>
  134. </view>
  135. <view class="description-text"> <text>{{ starInfo.content }}</text> </view>
  136. </view>
  137. <!-- 标签展示 -->
  138. <view class="description-box">
  139. <view class="description-title">
  140. <view>人物标签</view>
  141. </view>
  142. <view class="tags-box">
  143. <view class="tag-item" v-for="tag in starInfo.tags" :key="tag">
  144. {{ tag }}
  145. </view>
  146. </view>
  147. </view>
  148. </view>
  149. </view>
  150. <!-- 底部按钮 -->
  151. <view class="join-button" @tap="handleJoin"> 入驻星球 </view>
  152. </view>
  153. <SharePopup :visible="showShare" :share-url="shareUrl" :share-title="shareTitle" :share-desc="shareDesc"
  154. :share-img="shareImg" @close="showShare = false" />
  155. </view>
  156. </template>
  157. <script>
  158. import tabbarView from "@/components/tabbar/tabbar.vue";
  159. export default {
  160. components: {
  161. tabbarView,
  162. },
  163. data() {
  164. return {
  165. isLoading: false,
  166. selectedGender: null,
  167. tempGender: null,
  168. tabbars: [],
  169. ballColors: [
  170. "#FF6B6B", // 红色
  171. "#4ECDC4", // 青色
  172. "#45B7D1", // 蓝色
  173. "#96CEB4", // 绿色
  174. "#FFEEAD", // 黄色
  175. "#D4A5A5", // 粉色
  176. "#9A8194", // 紫色
  177. "#FF9F1C", // 橙色
  178. ],
  179. showForm: false,
  180. showError: false,
  181. formData: {
  182. nickname: "",
  183. gender: "其他",
  184. description: "",
  185. tags: [],
  186. },
  187. predefinedTags: [],
  188. showInfo: false,
  189. starImg: "",
  190. noteContent: "",
  191. starInfo: {},
  192. state: 5, //0 是用户输入星灵基因重组仓的状态 1 是用户已经完成了匹星灵展示页面 2是用户匹配中加载的状态 3是匹配到了待点击进入设置界面 (根据其它字段判断是否失败) 4是用户设置星灵信息的页面 5是用户查看星灵信息的页面 待入驻 6是用户已经已经入驻星球了
  193. sex: "",
  194. selectTags: [],
  195. info: {
  196. "id": 0,
  197. "sso_id": 0,
  198. "image_id": 0,
  199. "image": "",
  200. "nickname": "",
  201. "user_content": "",
  202. "content": "",
  203. "sex_id": 0,
  204. "tags": "",
  205. "status": 0
  206. },
  207. showShare: false,
  208. shareUrl: "https://your-share-url.com",
  209. shareTitle: "分享标题",
  210. shareDesc: "分享描述",
  211. shareImg: "https://your-share-image.com/image.jpg",
  212. };
  213. },
  214. onLoad() {
  215. this.getStar("get");
  216. },
  217. methods: {
  218. // 返回上一页
  219. goBack() {
  220. uni.navigateBack({
  221. delta: 1
  222. });
  223. },
  224. confirmGender() {
  225. if (!this.noteContent) return;
  226. // this.selectedGender = this.noteContent;
  227. this.isLoading = true;
  228. this.getStar("make");
  229. },
  230. goToSetProfile() {
  231. this.showForm = true;
  232. },
  233. toggleTag(tag) {
  234. const index = this.formData.tags.indexOf(tag);
  235. if (index > -1) {
  236. this.formData.tags.splice(index, 1);
  237. } else {
  238. this.formData.tags.push(tag);
  239. }
  240. },
  241. handleJoin() {
  242. console.log("入驻星球");
  243. // 处理入驻逻辑
  244. },
  245. getStar(act) {
  246. let that = this;
  247. console.log("uuid", getApp().globalData.uuid);
  248. // 设置加载状态
  249. if (act === "make") {
  250. this.isLoading = true;
  251. }
  252. uni.request({
  253. url: this.$apiHost + "/Work/getStar",
  254. data: {
  255. uuid: getApp().globalData.uuid,
  256. sex: this.tempGender,
  257. // noteContent: this.noteContent,
  258. act: act,
  259. },
  260. header: {
  261. "content-type": "application/json",
  262. sign: getApp().globalData.headerSign,
  263. },
  264. // 设置60秒超时
  265. timeout: 60000,
  266. success: (res) => {
  267. console.log("res.data", res.data);
  268. // res.data.have = 0
  269. if (res.data.have == 0) {
  270. this.showInfo = false;
  271. this.starImg = res.data.image;
  272. } else {
  273. //首次进来获取到了
  274. this.showInfo = true;
  275. }
  276. this.openContentPopUpWindow();
  277. if (res.data.success === "yes") {
  278. this.starImg = res.data.image;
  279. }
  280. if (res.data.info && res.data.info.tags != "") {
  281. let tags = res.data.info.tags.split(",");
  282. this.predefinedTags = tags.map(tag => ({
  283. text: tag,
  284. value: tag
  285. }));
  286. }
  287. this.starInfo = res.data.info || {};
  288. this.starInfo.tags = this.starInfo.tags.trim().split(",");
  289. console.log("starInfo", this.starInfo);
  290. this.formData.description = this.starInfo.content;
  291. if (act == "make") {
  292. // 模拟加载过程
  293. setTimeout(() => {
  294. that.isLoading = false;
  295. }, 300);
  296. }
  297. },
  298. fail: (err) => {
  299. console.error("请求失败:", err);
  300. // 显示错误提示
  301. uni.showToast({
  302. title: "网络请求失败,请重试",
  303. icon: "none",
  304. duration: 2000,
  305. });
  306. // 重置加载状态
  307. if (act === "make") {
  308. that.isLoading = false;
  309. }
  310. // 如果是网络超时,自动重试一次
  311. if (err.errMsg.includes("timeout")) {
  312. setTimeout(() => {
  313. console.log("请求超时,正在重试...");
  314. that.getStar(act);
  315. }, 1000);
  316. }
  317. },
  318. complete: () => {
  319. // 确保在任何情况下都能重置加载状态
  320. if (act === "make" && this.isLoading) {
  321. this.isLoading = false;
  322. }
  323. },
  324. });
  325. },
  326. // 提交用户 开始创建的命令
  327. apiPeiStar() {
  328. if (!this.noteContent) {
  329. uni.showToast({
  330. title: "请输入匹配条件",
  331. icon: "none",
  332. });
  333. return;
  334. }
  335. uni.request({
  336. url: this.$apiHost + "/AIpipei/start",
  337. data: {
  338. uuid: getApp().globalData.uuid,
  339. content: this.noteContent,
  340. },
  341. header: {
  342. "content-type": "application/json",
  343. sign: getApp().globalData.headerSign,
  344. },
  345. // 设置60秒超时
  346. timeout: 60000,
  347. methods: "POST",
  348. success: (res) => {
  349. console.log("开始AI匹配", res.data);
  350. state
  351. if (res.data.have == 0) {
  352. this.showInfo = false;
  353. this.starImg = res.data.image;
  354. } else {
  355. //首次进来获取到了
  356. this.showInfo = true;
  357. }
  358. this.openContentPopUpWindow();
  359. if (res.data.success === "yes") {
  360. this.starImg = res.data.image;
  361. }
  362. if (res.data.info && res.data.info.tags != "") {
  363. let tags = res.data.info.tags.split(",");
  364. this.predefinedTags = tags.map(tag => ({
  365. text: tag,
  366. value: tag
  367. }));
  368. }
  369. this.starInfo = res.data.info || {};
  370. this.starInfo.tags = this.starInfo.tags.trim().split(",");
  371. console.log("starInfo", this.starInfo);
  372. this.formData.description = this.starInfo.content;
  373. if (act == "make") {
  374. // 模拟加载过程
  375. setTimeout(() => {
  376. that.isLoading = false;
  377. }, 300);
  378. }
  379. },
  380. fail: (err) => {
  381. console.error("请求失败:", err);
  382. // 显示错误提示
  383. uni.showToast({
  384. title: "网络请求失败,请重试",
  385. icon: "none",
  386. duration: 2000,
  387. });
  388. // 重置加载状态
  389. if (act === "make") {
  390. that.isLoading = false;
  391. }
  392. // 如果是网络超时,自动重试一次
  393. if (err.errMsg.includes("timeout")) {
  394. setTimeout(() => {
  395. console.log("请求超时,正在重试...");
  396. that.getStar(act);
  397. }, 1000);
  398. }
  399. },
  400. complete: () => {
  401. // 确保在任何情况下都能重置加载状态
  402. if (act === "make" && this.isLoading) {
  403. this.isLoading = false;
  404. }
  405. },
  406. });
  407. },
  408. // 查询Ai匹配信息
  409. aIpipeiGetinfo(act) {
  410. uni.request({
  411. url: this.$apiHost + "/AIpipei/getinfo",
  412. data: {
  413. uuid: getApp().globalData.uuid,
  414. },
  415. header: {
  416. "content-type": "application/json",
  417. sign: getApp().globalData.headerSign,
  418. },
  419. // 设置60秒超时
  420. timeout: 60000,
  421. success: (res) => {
  422. console.log("查询到生成信息", res.data);
  423. },
  424. fail: (err) => {
  425. console.error("请求失败:", err);
  426. // 显示错误提示
  427. uni.showToast({
  428. title: "网络请求失败,请重试",
  429. icon: "none",
  430. duration: 2000,
  431. });
  432. // 如果是网络超时,自动重试一次
  433. if (err.errMsg.includes("timeout")) {
  434. setTimeout(() => {
  435. console.log("请求超时,正在重试...");
  436. that.aIpipeiGetinfo(act);
  437. }, 6000);
  438. }
  439. },
  440. complete: () => {
  441. },
  442. });
  443. },
  444. // 保存表单信息
  445. submitStar() {
  446. this.formData.tags = this.selectTags.join(",");
  447. this.state = 5
  448. return
  449. let that = this;
  450. uni.showLoading({
  451. mask: true,
  452. });
  453. uni.request({
  454. url: this.$apiHost + "/AIpipei/save",
  455. data: {
  456. uuid: getApp().globalData.uuid,
  457. sex: this.tempGender,
  458. // noteContent: this.noteContent,
  459. name: this.formData.nickname,
  460. content: this.formData.description,
  461. },
  462. header: {
  463. "content-type": "application/json",
  464. sign: getApp().globalData.headerSign,
  465. },
  466. // 设置60秒超时
  467. timeout: 10000,
  468. success: (res) => {
  469. console.log("res.data", res.data);
  470. uni.showToast({
  471. title: res.data.str,
  472. icon: "none",
  473. duration: 2000,
  474. });
  475. if (res.data.success === "yes") {
  476. setTimeout(() => {
  477. that.aIpipeiGetinfo();
  478. }, 300);
  479. }
  480. },
  481. fail: (err) => {
  482. console.error("请求失败:", err);
  483. // 显示错误提示
  484. uni.showToast({
  485. title: "网络请求失败,请重试",
  486. icon: "none",
  487. duration: 2000,
  488. });
  489. },
  490. complete: () => {
  491. uni.hideLoading();
  492. },
  493. });
  494. },
  495. selectGender(option) {
  496. this.formData.sex = option;
  497. this.sex = option;
  498. },
  499. openContentPopUpWindow() {
  500. if (this.$refs.openContentPopUpWindow) {
  501. this.$refs.openContentPopUpWindow.open();
  502. }
  503. },
  504. closeContentPopUpWindow() {
  505. if (this.$refs.openContentPopUpWindow) {
  506. this.$refs.openContentPopUpWindow.close();
  507. }
  508. },
  509. },
  510. };
  511. </script>
  512. <style lang="scss">
  513. @import "./myStar.scss";
  514. .openContentPopUpWindow {
  515. ::v-deep.uv-textarea {
  516. width: 694rpx !important;
  517. border-radius: 20rpx !important;
  518. border: 1rpx solid #000000 !important;
  519. margin: 0 auto;
  520. margin-bottom: 44rpx;
  521. min-height: 300rpx;
  522. padding-bottom: 40rpx;
  523. .uv-textarea__field {
  524. min-height: 200rpx !important;
  525. font-weight: 400;
  526. font-size: 28rpx;
  527. color: #999999;
  528. }
  529. }
  530. }
  531. .textarea-container {
  532. .textarea {
  533. background: #f2f6f2 !important;
  534. min-height: 100rpx;
  535. }
  536. }
  537. .tags-container {
  538. ::v-deep.checklist-box {
  539. border-radius: 16rpx !important;
  540. border: 2rpx solid #1f1f1f !important;
  541. background-color: #fff !important;
  542. display: flex;
  543. align-items: center;
  544. justify-content: center;
  545. .checklist-text {
  546. font-size: 28rpx;
  547. color: #1f1f1f;
  548. font-family: "PingFang SC-Bold" !important;
  549. }
  550. &.is-checked {
  551. background: #f7ffea !important;
  552. border-color: #7ebc00 !important;
  553. .checklist-text {
  554. color: #1f1f1f !important;
  555. }
  556. }
  557. }
  558. }
  559. .star-container {
  560. /* 自定义导航栏样式 */
  561. .custom-navbar {
  562. display: flex;
  563. flex-direction: row;
  564. align-items: center;
  565. justify-content: space-between;
  566. width: 100%;
  567. height: 90rpx;
  568. padding: 0 20rpx;
  569. padding-top: var(--status-bar-height);
  570. background-color: transparent;
  571. position: fixed;
  572. top: 0;
  573. left: 0;
  574. z-index: 100;
  575. background: transparent;
  576. &::before {
  577. content: '';
  578. position: absolute;
  579. top: 0;
  580. left: 0;
  581. width: 100%;
  582. height: var(--status-bar-height);
  583. background-color: #fff;
  584. z-index: -1;
  585. }
  586. .navbar-left {
  587. width: 80rpx;
  588. height: 80rpx;
  589. display: flex;
  590. align-items: center;
  591. justify-content: center;
  592. .fa-angle-left {
  593. font-size: 48rpx;
  594. color: #333;
  595. }
  596. }
  597. .navbar-right {
  598. width: 80rpx;
  599. height: 80rpx;
  600. display: flex;
  601. justify-content: center;
  602. align-items: center;
  603. .fa-ellipsis-h {
  604. font-size: 36rpx;
  605. color: #333;
  606. }
  607. }
  608. }
  609. }
  610. </style>