myStar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. <template>
  2. <view class="star-container">
  3. <PageHeader title="" class="PageHeader" v-if="state == 1 && false">
  4. <template slot="center"> </template>
  5. </PageHeader>
  6. <!-- 星灵基因重组仓弹窗 -->
  7. <view class="gender-popup" v-if="!noteContent && !showInfo && 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="isLoading">
  18. <image src="../../static/me/loadAnimation.gif" mode="widthFix"></image>
  19. </view>
  20. <!-- 角色展示页面 -->
  21. <view class="character-page" v-else-if="noteContent || true">
  22. <view class="character-container">
  23. <image :src="starImg||'https://e.zhichao.art/AI_images/b_3_92.png'" mode="aspectFit" class="character-image"></image>
  24. </view>
  25. <view class="bottom-button" @tap="goToSetProfile"> 设置星灵简介 </view>
  26. </view>
  27. <!-- 角色信息展示页面 -->
  28. <view class="character-info" v-else-if="showInfo ">
  29. <view class="info-container">
  30. <!-- 角色立绘区域 -->
  31. <view class="character-portrait">
  32. <image :src="starInfo.image" mode="aspectFit" class="portrait-image"></image>
  33. <text class="character-name">{{ starInfo.name }}</text>
  34. </view>
  35. <!-- 角色信息板块 -->
  36. <view class="info-section">
  37. <view class="section-title">关于Ta</view>
  38. <!-- 人物简介 -->
  39. <view class="description-box">
  40. <text class="description-text">{{ starInfo.content }}</text>
  41. </view>
  42. <!-- 标签展示 -->
  43. <view class="tags-box">
  44. <view class="tag-item" v-for="tag in formData.tags" :key="tag">
  45. {{ tag }}
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- 底部按钮 -->
  51. <view class="join-button" @tap="handleJoin"> 入驻星球 </view>
  52. </view>
  53. <!-- 表单页面 -->
  54. <view class="form-page" v-else-if="showForm">
  55. <PageHeader title="设置星灵简介" class="PageHeader">
  56. <template slot="center"> </template>
  57. </PageHeader>
  58. <view class="reserveASeat"></view>
  59. <form @submit="submitForm">
  60. <view class="form-group">
  61. <view class="label">
  62. <text class="required">*</text>
  63. <text>昵称</text>
  64. </view>
  65. <input class="input" v-model="formData.nickname" placeholder="给星灵取个名字"
  66. :class="{ error: showError && !formData.nickname }" />
  67. </view>
  68. <view class="form-group">
  69. <view class="label">性别</view>
  70. <view class="gender-options">
  71. <view class="gender-option" :class="sex == 'male' ? 'selected' : ''">
  72. <view class="gender-icon male" @tap="selectGender('male')">
  73. <image src="../../static/me/wd_icon_nan.png" mode="aspectFit"></image>
  74. 男性
  75. </view>
  76. </view>
  77. <view class="gender-option" :class="sex == 'female' ? 'selected' : ''">
  78. <view class="gender-icon female" @tap="selectGender('female')">
  79. <image src="../../static/me/wd_icon_nv.png" mode="aspectFit"></image>
  80. 女性
  81. </view>
  82. </view>
  83. <view class="gender-option" :class="sex == 'other' ? 'selected' : ''">
  84. <view class="gender-icon other" @tap="selectGender('other')">
  85. <image src="../../static/me/wd_icon_qita.png" mode="aspectFit"></image>
  86. 其它
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. <view class="form-group">
  92. <view class="label">
  93. <text class="required">*</text>
  94. <text>人物简介</text>
  95. </view>
  96. <view class="textarea-container">
  97. <textarea class="textarea" v-model="formData.description"
  98. placeholder="填写这个角色的人物介绍,例如性格、身份、背景与历程..." :maxlength="500"
  99. :class="{ error: showError && !formData.description }" autoHeight />
  100. <text class="word-count">{{ formData.description.length }}/500</text>
  101. </view>
  102. </view>
  103. <view class="form-group">
  104. <view class="label">人物标签</view>
  105. <!-- <scroll-view class="tags-scroll" scroll-x="true" show-scrollbar="false">
  106. <view class="tags-container">
  107. <view class="tag" v-for="tag in predefinedTags" :key="tag">
  108. {{ tag }}
  109. </view>
  110. </view>
  111. </scroll-view> -->
  112. <view class="tags-container">
  113. <!-- <view class="tag" :class="{ active: tagSet.has(tag) }" v-for="tag in predefinedTags" :key="tag"
  114. @tap="switchTag(tag)">
  115. {{ tag }}
  116. </view> -->
  117. <uni-data-checkbox mode="tag" multiple v-model="selectTags"
  118. :localdata="predefinedTags"></uni-data-checkbox>
  119. </view>
  120. </view>
  121. </form>
  122. <view class="submit-button" @tap="submitStar"> 确定并提交 </view>
  123. </view>
  124. <!-- 收藏内容区域 -->
  125. <view class="star-content" v-else>
  126. <view class="star-list">
  127. <!-- 这里放收藏列表内容 -->
  128. </view>
  129. </view>
  130. </view>
  131. </template>
  132. <script>
  133. import tabbarView from "@/components/tabbar/tabbar.vue";
  134. export default {
  135. components: {
  136. tabbarView,
  137. },
  138. data() {
  139. return {
  140. isLoading: false,
  141. selectedGender: null,
  142. tempGender: null,
  143. tabbars: [],
  144. ballColors: [
  145. "#FF6B6B", // 红色
  146. "#4ECDC4", // 青色
  147. "#45B7D1", // 蓝色
  148. "#96CEB4", // 绿色
  149. "#FFEEAD", // 黄色
  150. "#D4A5A5", // 粉色
  151. "#9A8194", // 紫色
  152. "#FF9F1C", // 橙色
  153. ],
  154. showForm: false,
  155. showError: false,
  156. formData: {
  157. nickname: "",
  158. gender: "其他",
  159. description: "",
  160. tags: [],
  161. },
  162. predefinedTags: [],
  163. showInfo: false,
  164. starImg: "",
  165. noteContent: "",
  166. starInfo: {},
  167. state: 1,
  168. sex: "",
  169. selectTags: [],
  170. };
  171. },
  172. onLoad() {
  173. this.getStar("get");
  174. },
  175. methods: {
  176. confirmGender() {
  177. if (!this.noteContent) return;
  178. // this.selectedGender = this.noteContent;
  179. this.isLoading = true;
  180. this.getStar("make");
  181. },
  182. goToSetProfile() {
  183. this.showForm = true;
  184. },
  185. toggleTag(tag) {
  186. const index = this.formData.tags.indexOf(tag);
  187. if (index > -1) {
  188. this.formData.tags.splice(index, 1);
  189. } else {
  190. this.formData.tags.push(tag);
  191. }
  192. },
  193. handleJoin() {
  194. console.log("入驻星球");
  195. // 处理入驻逻辑
  196. },
  197. getStar(act) {
  198. let that = this;
  199. console.log("uuid", getApp().globalData.uuid);
  200. // 设置加载状态
  201. if (act === "make") {
  202. this.isLoading = true;
  203. }
  204. uni.request({
  205. url: this.$apiHost + "/Work/getStar",
  206. data: {
  207. uuid: getApp().globalData.uuid,
  208. sex: this.tempGender,
  209. // noteContent: this.noteContent,
  210. act: act,
  211. },
  212. header: {
  213. "content-type": "application/json",
  214. sign: getApp().globalData.headerSign,
  215. },
  216. // 设置60秒超时
  217. timeout: 60000,
  218. success: (res) => {
  219. console.log("res.data", res.data);
  220. // res.data.have = 0
  221. if (res.data.have == 0) {
  222. this.showInfo = false;
  223. this.starImg = res.data.image;
  224. } else {
  225. //首次进来获取到了
  226. this.showInfo = true;
  227. }
  228. this.openContentPopUpWindow();
  229. if (res.data.success === "yes") {
  230. this.starImg = res.data.image;
  231. }
  232. if (res.data.info && res.data.info.tags != "") {
  233. let tags = res.data.info.tags.split(",");
  234. this.predefinedTags = tags.map(tag => ({
  235. text: tag,
  236. value: tag
  237. }));
  238. }
  239. this.starInfo = res.data.info || {};
  240. console.log("starInfo", this.starInfo);
  241. this.formData.description = this.starInfo.content;
  242. if (act == "make") {
  243. // 模拟加载过程
  244. setTimeout(() => {
  245. that.isLoading = false;
  246. }, 300);
  247. }
  248. },
  249. fail: (err) => {
  250. console.error("请求失败:", err);
  251. // 显示错误提示
  252. uni.showToast({
  253. title: "网络请求失败,请重试",
  254. icon: "none",
  255. duration: 2000,
  256. });
  257. // 重置加载状态
  258. if (act === "make") {
  259. that.isLoading = false;
  260. }
  261. // 如果是网络超时,自动重试一次
  262. if (err.errMsg.includes("timeout")) {
  263. setTimeout(() => {
  264. console.log("请求超时,正在重试...");
  265. that.getStar(act);
  266. }, 1000);
  267. }
  268. },
  269. complete: () => {
  270. // 确保在任何情况下都能重置加载状态
  271. if (act === "make" && this.isLoading) {
  272. this.isLoading = false;
  273. }
  274. },
  275. });
  276. },
  277. submitStar() {
  278. let that = this;
  279. uni.showLoading({
  280. mask: true,
  281. });
  282. uni.request({
  283. url: this.$apiHost + "/Work/getStar",
  284. data: {
  285. uuid: getApp().globalData.uuid,
  286. sex: this.tempGender,
  287. // noteContent: this.noteContent,
  288. name: this.formData.nickname,
  289. content: this.formData.description,
  290. act: "submit",
  291. },
  292. header: {
  293. "content-type": "application/json",
  294. sign: getApp().globalData.headerSign,
  295. },
  296. // 设置60秒超时
  297. timeout: 10000,
  298. success: (res) => {
  299. console.log("res.data", res.data);
  300. uni.showToast({
  301. title: res.data.str,
  302. icon: "none",
  303. duration: 2000,
  304. });
  305. if (res.data.success === "yes") {
  306. setTimeout(() => {
  307. that.getStar("get");
  308. }, 300);
  309. }
  310. },
  311. fail: (err) => {
  312. console.error("请求失败:", err);
  313. // 显示错误提示
  314. uni.showToast({
  315. title: "网络请求失败,请重试",
  316. icon: "none",
  317. duration: 2000,
  318. });
  319. },
  320. complete: () => {
  321. uni.hideLoading();
  322. },
  323. });
  324. },
  325. selectGender(option) {
  326. this.formData.sex = option;
  327. this.sex = option;
  328. },
  329. openContentPopUpWindow() {
  330. if (this.$refs.openContentPopUpWindow) {
  331. this.$refs.openContentPopUpWindow.open();
  332. }
  333. },
  334. closeContentPopUpWindow() {
  335. if (this.$refs.openContentPopUpWindow) {
  336. this.$refs.openContentPopUpWindow.close();
  337. }
  338. },
  339. },
  340. };
  341. </script>
  342. <style lang="scss">
  343. @import "./myStar.scss";
  344. .openContentPopUpWindow {
  345. ::v-deep.uv-textarea {
  346. width: 694rpx !important;
  347. border-radius: 20rpx !important;
  348. border: 1rpx solid #000000 !important;
  349. margin: 0 auto;
  350. margin-bottom: 44rpx;
  351. min-height: 300rpx;
  352. padding-bottom: 40rpx;
  353. .uv-textarea__field {
  354. min-height: 200rpx !important;
  355. font-weight: 400;
  356. font-size: 28rpx;
  357. color: #999999;
  358. }
  359. }
  360. }
  361. .textarea-container {
  362. .textarea {
  363. background: #f2f6f2 !important;
  364. min-height: 100rpx;
  365. }
  366. }
  367. .tags-container {
  368. ::v-deep.checklist-box {
  369. border-radius: 16rpx;
  370. border: 2rpx solid #1f1f1f !important;
  371. background-color: #fff !important;
  372. display: flex;
  373. align-items: center;
  374. justify-content: center;
  375. .checklist-text {
  376. font-size: 28rpx;
  377. color: #1f1f1f;
  378. font-family: "PingFang SC-Bold" !important;
  379. }
  380. &.is-checked{
  381. background: #f7ffea !important;
  382. border-color: #7ebc00 !important;
  383. .checklist-text {
  384. color:#1f1f1f !important;
  385. }
  386. }
  387. }
  388. }
  389. </style>