step.vue 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507
  1. <template>
  2. <view class="step-container">
  3. <view class="reserveASeat"></view>
  4. <!-- 步骤指示器 -->
  5. <view class="step-header">
  6. <text class="step-number">STEP {{ currentStep }}</text>
  7. <view class="progress-container">
  8. <view class="progress-bar">
  9. <view class="progress-inner" :style="{ width: currentStep === 1 ? '50%' : '100%' }"></view>
  10. </view>
  11. </view>
  12. </view>
  13. <!-- 步骤1:个人信息 -->
  14. <view v-if="currentStep === 1" class="step-content">
  15. <view class="step-title">这里是 <text>·灵魂汇聚·</text> 的起点</view>
  16. <!-- 头像上传 -->
  17. <view class="avatar-section">
  18. <view class="avatar-wrapper" @click="chooseAvatar">
  19. <CircleAvatar v-if="userInfo.avatar" class="avator" :src="userInfo.avatar"></CircleAvatar>
  20. <view class="avatar-placeholder">
  21. <image src="/static/me/photo.png" mode="aspectFit" class="camera-icon"></image>
  22. </view>
  23. </view>
  24. </view>
  25. <!-- 昵称输入 -->
  26. <view class="input-section">
  27. <view class="input-label">我的名字</view>
  28. <view class="input-wrapper">
  29. <input type="text" v-model="userInfo.nickname" placeholder="取一个独一无二的名字吧~"
  30. placeholder-class="input-placeholder" maxlength="10" />
  31. <view class="input-actions">
  32. <image src="/static/me/step/dlzc_icon_suiji.png" mode="aspectFit" class="action-icon random"
  33. @click="generateRandomNickname"></image>
  34. </view>
  35. </view>
  36. </view>
  37. <!-- 性别选择 -->
  38. <view class="gender-section">
  39. <view class="input-label">性别</view>
  40. <view class="gender-options">
  41. <view class="gender-item" :class="{ active: userInfo.gender === '1' }" @click="userInfo.gender = '1'">
  42. <image src="/static/me/step/dlzc_icon_nan.png" mode="aspectFit" class="gender-icon"></image>
  43. <text>男生</text>
  44. </view>
  45. <view class="gender-item" :class="{ active: userInfo.gender === '2' }" @click="userInfo.gender = '2'">
  46. <image src="/static/me/step/dlzc_icon_nv.png" mode="aspectFit" class="gender-icon"></image>
  47. <text>女生</text>
  48. </view>
  49. <view class="gender-item" :class="{ active: userInfo.gender === '3' }" @click="userInfo.gender = '3'">
  50. <image src="/static/me/step/dlzc_icon_qita.png" mode="aspectFit" class="gender-icon"></image>
  51. <text>其它</text>
  52. </view>
  53. </view>
  54. </view>
  55. <!-- 生日选择 -->
  56. <view class="birthday-section">
  57. <view class="input-label">我的生日</view>
  58. <view class="birthday-picker" @click="openCalendar">
  59. <view class="uni-input">
  60. <text :class="{ placeholder: !userInfo.birthday }">{{
  61. userInfo.birthday || "选择生日"
  62. }}</text>
  63. <text v-if="userInfo.birthday" class="constellation">{{
  64. userInfo.xinzuo
  65. }}</text>
  66. </view>
  67. <image src="/static/me/step/dlzc_icon_arrow.png" mode="aspectFit" class="arrow-icon"></image>
  68. </view>
  69. <uni-calendar :date="userInfo.birthday||'2000-01-01'" ref="calendar" :insert="false" @confirm="confirmBirthday" />
  70. </view>
  71. </view>
  72. <!-- 步骤2:兴趣选择 -->
  73. <view v-if="currentStep === 2" class="step-content">
  74. <view class="step-title">亦是 <text>·奇思妙想·</text> 的原野</view>
  75. <view class="interest-section">
  76. <text class="interest-tip">请选择</text>
  77. <view class="interest-circles" @touchstart="handleTouchStart" @touchmove="handleTouchMove"
  78. @touchend="handleTouchEnd">
  79. <view class="interest-circles-container" :style="getContainerStyle()">
  80. <view v-for="(interest, index) in interests" :key="index" class="interest-circle-box" :class="{
  81. active: selectedInterests.includes(interest.id),
  82. disabled:
  83. !selectedInterests.includes(interest.id) && isMaxSelected,
  84. }" @click="toggleInterest(interest.id)" :style="getCircleStyle(index)">
  85. <view class="interest-circle">
  86. <view>{{ interest.name }}</view>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. <!-- 添加兴趣爱好 -->
  92. <view class="add-interests">
  93. <view class="add-title">
  94. 添加兴趣爱好
  95. <text class="add-hint">(最多选择5个)</text>
  96. </view>
  97. <view class="interest-tags">
  98. <view v-for="(tag, index) in selectedTags" :key="index" class="interest-tag">
  99. {{ tag.name }}
  100. <text class="remove-tag" @click.stop="removeTag(tag)">×</text>
  101. </view>
  102. <view class="add-tag" @click="showPopup" v-if="!isMaxSelected">
  103. <image src="/static/me/step/dlzc_icon_tianjia.png" mode="aspectFit" class="add-icon"></image>
  104. 创建新偏好
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. <!-- 底部按钮 -->
  111. <view class="bottom-button" @click="handleNext">
  112. {{ currentStep === 1 ? "下一步" : "完成" }}
  113. </view>
  114. <!-- 添加标签弹窗 -->
  115. <uni-popup ref="addTagPopup" type="center" :mask-click="false">
  116. <view class="add-tag-popup">
  117. <view class="popup-title">创建新偏好</view>
  118. <scroll-view scroll-y class="popup-content" :scroll-top="scrollTop" @scroll="onScroll">
  119. <view class="popup-input">
  120. <input type="text" v-model="newTag" :disabled="isMaxSelected" :placeholder="isMaxSelected ? '已达到标签上限' : '输入您的兴趣爱好'
  121. " placeholder-style="color: #999999;" maxlength="5" @confirm="addNewTag" class="tag-input"
  122. :class="{ disabled: isMaxSelected }" />
  123. </view>
  124. <view class="selected-tags" v-if="selectedTags.length > 0">
  125. <view class="selected-tags-title">
  126. 已选标签 ({{ selectedTags.length }}/{{ maxTags }})
  127. <text v-if="isMaxSelected" class="max-hint">已达到上限</text>
  128. </view>
  129. <view class="selected-tags-list">
  130. <view v-for="(tag, index) in selectedTags" :key="index" class="selected-tag">
  131. {{ tag.name }}
  132. <text class="remove-tag" @click.stop="removeTag(tag)">×</text>
  133. </view>
  134. </view>
  135. </view>
  136. </scroll-view>
  137. <view class="popup-buttons">
  138. <button class="btn-cancel" @click="closePopup">再考虑一下</button>
  139. <button class="btn-confirm" :class="{ disabled: isMaxSelected || !newTag.trim() }" @click="addNewTag">
  140. 确认添加
  141. </button>
  142. </view>
  143. </view>
  144. </uni-popup>
  145. <!-- 权限申请提示 -->
  146. <!-- <view v-if="showRights" style="
  147. width: 100%;
  148. height: 300rpx;
  149. background-color: rgba(255, 255, 255, 0.9);
  150. position: fixed;
  151. top: 0;
  152. display: flex;
  153. flex-direction: column;
  154. justify-content: center;
  155. align-items: center;
  156. z-index: 999;">
  157. <text style="
  158. width: 90%;
  159. color: #000000;
  160. font-size: 38rpx;
  161. text-align: left;
  162. padding: 10rpx 20rpx;
  163. padding-top: 10rpx;">正在获取相机、存储权限</text>
  164. <text style="
  165. width: 90%;
  166. color: #666666;
  167. font-size: 28rpx;
  168. text-align: left;
  169. padding: 10rpx 20rpx;">该权限用于获取设备拍摄或获取本地应用相册,进行头像或图片上传。</text>
  170. </view> -->
  171. </view>
  172. </template>
  173. <script>
  174. import permission from '@/common/permission.js';
  175. export default {
  176. components: {
  177. },
  178. data() {
  179. return {
  180. currentStep: 1,
  181. userInfo: {
  182. avatar: "",
  183. nickname: "",
  184. gender: "",
  185. birthday: "",
  186. xinzuo: "",
  187. },
  188. interests: [
  189. { id: 1, name: "老二次元了" },
  190. { id: 2, name: "coser" },
  191. { id: 3, name: "沉迷音乐-Hop" },
  192. { id: 4, name: "网游小达人" },
  193. { id: 5, name: "AJ控" },
  194. { id: 6, name: "白日梦想家" },
  195. { id: 7, name: "撸铁狂魔" },
  196. { id: 8, name: "古风汉服" },
  197. { id: 9, name: "爱画画" },
  198. { id: 10, name: "数码极客" },
  199. { id: 11, name: "盲盒玩家" },
  200. { id: 12, name: "三坑玩家" },
  201. { id: 13, name: "动漫达人" },
  202. { id: 14, name: "设计师" },
  203. { id: 15, name: "爱卡通" },
  204. { id: 16, name: "兜风去" },
  205. { id: 17, name: "爱夜跑" },
  206. { id: 18, name: "街头滑板" },
  207. { id: 19, name: "球类运动" },
  208. { id: 20, name: "lo娘" },
  209. { id: 21, name: "rapper" },
  210. { id: 22, name: "时尚达人" },
  211. { id: 23, name: "机甲狂潮" },
  212. { id: 24, name: "养宠物" },
  213. { id: 25, name: "风轻云淡" },
  214. { id: 26, name: "养多肉" },
  215. { id: 27, name: "热爱自然" },
  216. { id: 28, name: "赛博朋克" },
  217. { id: 29, name: "骨子里高冷" },
  218. { id: 30, name: "爱唠嗑" },
  219. { id: 31, name: "资深中二" },
  220. { id: 32, name: "天然呆" },
  221. { id: 33, name: "思想家" },
  222. { id: 34, name: "极度抽象" },
  223. { id: 35, name: "学院派" },
  224. { id: 36, name: "平平无奇" },
  225. { id: 37, name: "热情奔放" },
  226. { id: 38, name: "博古通今" },
  227. { id: 39, name: "labubu粉" },
  228. { id: 40, name: "玛特收藏家" },
  229. ],
  230. selectedInterests: [],
  231. showAddTag: false,
  232. newTag: "",
  233. endDate: "",
  234. circleConfig: {
  235. size: 132,
  236. gap: 30,
  237. rowGap: 20,
  238. offsetLefts: 30,
  239. offsetTops: 20,
  240. rows: 4,
  241. baseTop: 30,
  242. baseLeft: 30,
  243. },
  244. containerWidth: 0,
  245. customTags: [],
  246. maxTags: 5,
  247. scrollTop: 0,
  248. xinzuo: [
  249. "水瓶座",
  250. "双鱼座",
  251. "白羊座",
  252. "金牛座",
  253. "双子座",
  254. "巨蟹座",
  255. "狮子座",
  256. "处女座",
  257. "天秤座",
  258. "天蝎座",
  259. "射手座",
  260. "摩羯座",
  261. ],
  262. showRights: false,
  263. skey: getApp().globalData.skey,
  264. imglocal: "",
  265. };
  266. },
  267. computed: {
  268. totalWidth() {
  269. const { size, gap, rows } = this.circleConfig;
  270. const columns = Math.ceil(this.interests.length / rows);
  271. return columns * (size + gap) + gap + "rpx";
  272. },
  273. selectedTags() {
  274. const selectedPresets = this.interests
  275. .filter((interest) => this.selectedInterests.includes(interest.id))
  276. .map((interest) => ({
  277. id: interest.id,
  278. name: interest.name,
  279. isPreset: true,
  280. }));
  281. return [...selectedPresets, ...this.customTags];
  282. },
  283. isMaxSelected() {
  284. return this.selectedTags.length >= this.maxTags;
  285. },
  286. },
  287. onLoad() {
  288. this.currentStep = 1;
  289. const now = new Date();
  290. const year = now.getFullYear();
  291. const month = String(now.getMonth() + 1).padStart(2, "0");
  292. const day = String(now.getDate()).padStart(2, "0");
  293. this.endDate = `${year}-${month}-${day}`;
  294. // 页面加载时获取用户信息
  295. this.getInfoData();
  296. },
  297. onShow() { },
  298. methods: {
  299. onBack() { },
  300. chkSel() {
  301. if (this.sel == 1) {
  302. this.sel = 0;
  303. } else {
  304. this.sel = 1;
  305. }
  306. },
  307. chkSex(sex) {
  308. this.sex = sex;
  309. },
  310. delTag(tg) {
  311. let list_tag2 = [];
  312. for (let i = 0; i < this.sel_tags.length; i++) {
  313. if (this.sel_tags[i] != tg && this.sel_tags[i] != "") {
  314. list_tag2.push(this.sel_tags[i]);
  315. }
  316. }
  317. this.sel_tags = list_tag2;
  318. },
  319. selTags(itm) {
  320. let that = this;
  321. let isIn = false;
  322. for (let entry of this.sel_tags) {
  323. // console.log(entry); // 1, "string", false
  324. if (entry == itm) {
  325. isIn = true;
  326. break;
  327. }
  328. }
  329. return isIn;
  330. },
  331. chkTag(itm) {
  332. if (this.selTags(itm)) {
  333. let tmpTags = [];
  334. for (let entry of this.sel_tags) {
  335. // console.log(entry); // 1, "string", false
  336. if (entry != itm && entry != "") {
  337. tmpTags.push(entry);
  338. }
  339. }
  340. this.sel_tags = tmpTags;
  341. } else {
  342. if (this.sel_tags.length >= 5) {
  343. this.$refs["ToastW3"].showToast({
  344. title: "最多选择5个标签",
  345. animation: 0,
  346. });
  347. return;
  348. }
  349. this.sel_tags.push(itm);
  350. }
  351. },
  352. sliderChange1(e) {
  353. this.age = e.detail.value;
  354. },
  355. sliderChange2(e) {
  356. this.height = e.detail.value;
  357. },
  358. sliderChange3(e) {
  359. this.weight = e.detail.value;
  360. },
  361. SetXueli() {
  362. let that = this;
  363. uni.showActionSheet({
  364. itemColor: "#000000",
  365. itemList: this.xueli,
  366. success: function (res) {
  367. that.xueli_sel = that.xueli[res.tapIndex];
  368. // console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
  369. },
  370. fail: function (res) {
  371. console.log(res.errMsg);
  372. },
  373. });
  374. },
  375. SetXinzuo() {
  376. let that = this;
  377. uni.showActionSheet({
  378. itemColor: "#000000",
  379. itemList: this.xinzuo,
  380. success: function (res) {
  381. that.xinzuo_sel = that.xinzuo[res.tapIndex];
  382. // console.log('选中了第' + (res.tapIndex + 1) + '个按钮');
  383. },
  384. fail: function (res) {
  385. console.log(res.errMsg);
  386. },
  387. });
  388. },
  389. getInfoData() {
  390. console.log(this.$apiHost + "/Member/getinfoData");
  391. uni.request({
  392. url: this.$apiHost + "/Member/getinfoData",
  393. data: {
  394. uuid: getApp().globalData.uuid,
  395. },
  396. header: {
  397. "content-type": "application/json",
  398. },
  399. success: (res) => {
  400. console.log("res", res.data);
  401. if (res.data) {
  402. // 根据返回数据设置用户信息
  403. this.userInfo = {
  404. ...this.userInfo,
  405. nickname: res.data.nickname || "",
  406. gender: res.data.sex ? String(res.data.sex) : "",
  407. birthday: res.data.birthday || "",
  408. xinzuo: res.data.xinzuo || "",
  409. };
  410. if (res.data.avator) {
  411. this.userInfo.avatar = res.data.avator;
  412. }
  413. // 如果有兴趣爱好,解析并设置
  414. if (res.data.aihao && res.data.aihao.length > 0) {
  415. // 解析爱好标签
  416. const aihaos = res.data.aihao.split(",");
  417. // 处理预设兴趣
  418. const presetTags = [];
  419. const customTags = [];
  420. aihaos.forEach((tag) => {
  421. // 查找是否是预设兴趣
  422. const matchedInterest = this.interests.find(
  423. (i) => i.name === tag
  424. );
  425. if (matchedInterest) {
  426. presetTags.push(matchedInterest.id);
  427. } else if (tag.trim()) {
  428. customTags.push({
  429. name: tag,
  430. isCustom: true,
  431. });
  432. }
  433. });
  434. this.selectedInterests = presetTags;
  435. this.customTags = customTags;
  436. }
  437. }
  438. },
  439. fail: (err) => {
  440. console.error("获取用户信息失败", err);
  441. uni.showToast({
  442. title: "获取信息失败,请重试",
  443. icon: "none",
  444. });
  445. },
  446. });
  447. },
  448. submitUserInfo() {
  449. // 收集所有标签
  450. let tagStr = this.selectedTags.map((item) => item.name).join(",");
  451. // 构建提交的数据对象
  452. const data = {
  453. uuid: getApp().globalData.uuid,
  454. nickname: this.userInfo.nickname,
  455. avator: this.userInfo.avatar,
  456. sex: this.userInfo.gender,
  457. birthday: this.userInfo.birthday,
  458. xinzuo: this.userInfo.xinzuo,
  459. aihao: tagStr,
  460. };
  461. uni.showLoading({
  462. title: "保存中...",
  463. mask: true,
  464. });
  465. uni.request({
  466. url: this.$apiHost + "/Member/setinfoData",
  467. data: data,
  468. method: "POST",
  469. header: {
  470. "Content-Type": "application/x-www-form-urlencoded",
  471. sign: getApp().globalData.headerSign,
  472. },
  473. dataType: "json",
  474. success: (res) => {
  475. if (res.data.success === "yes") {
  476. // 保存用户信息到全局变量和本地存储
  477. if (this.userInfo.nickname) {
  478. getApp().globalData.nickname = this.userInfo.nickname;
  479. uni.setStorageSync("nickname", this.userInfo.nickname);
  480. }
  481. if (this.userInfo.avatar) {
  482. getApp().globalData.avator = this.userInfo.avatar;
  483. uni.setStorageSync("avator", this.userInfo.avatar);
  484. }
  485. uni.showToast({
  486. title: "注册成功",
  487. icon: "success",
  488. });
  489. // 延迟跳转
  490. setTimeout(() => {
  491. uni.switchTab({
  492. url: "/pages/index/index",
  493. });
  494. }, 1500);
  495. } else {
  496. uni.showToast({
  497. title: res.data.str || "保存失败",
  498. icon: "none",
  499. });
  500. }
  501. },
  502. fail: () => {
  503. uni.showToast({
  504. title: "网络错误",
  505. icon: "none",
  506. });
  507. },
  508. complete: () => {
  509. uni.hideLoading();
  510. },
  511. });
  512. },
  513. chooseAvatar() {
  514. uni.showActionSheet({
  515. itemList: ['拍照', '从相册选择'],
  516. success: (res) => {
  517. const sourceType = res.tapIndex === 0 ? 'camera' : 'album';
  518. this.chooseImage(sourceType);
  519. }
  520. });
  521. },
  522. async chooseImage(sourceType) {
  523. try {
  524. let hasPermission = false;
  525. if (sourceType === 'camera') {
  526. hasPermission = await this.checkCameraPermission();
  527. } else if (sourceType === 'album') {
  528. hasPermission = await this.checkPhotoLibraryPermission();
  529. }
  530. if (!hasPermission) {
  531. uni.showToast({
  532. title: '未获得权限',
  533. icon: 'none'
  534. });
  535. return;
  536. }
  537. uni.chooseImage({
  538. count: 1,
  539. sizeType: ['compressed'],
  540. sourceType: [sourceType],
  541. success: async (res) => {
  542. console.log('res:', res)
  543. if (res.tempFilePaths.length > 0) {
  544. this.userInfo.avatar = res.tempFilePaths[0]; // 立即显示选择的图片
  545. const tempFilePath = res.tempFilePaths[0];
  546. console.log('tempFilePaths:', tempFilePath);
  547. await this.uploadImage(tempFilePath);
  548. }
  549. },
  550. fail: (err) => {
  551. console.error('选择图片失败:', err);
  552. uni.showToast({
  553. title: '选择图片失败',
  554. icon: 'none'
  555. });
  556. }
  557. });
  558. } catch (error) {
  559. console.error('权限检查失败:', error);
  560. uni.showToast({
  561. title: '权限检查失败',
  562. icon: 'none'
  563. });
  564. }
  565. },
  566. async checkCameraPermission() {
  567. const hasPermission = await permission.request(permission.PermissionType.CAMERA, {
  568. title: "“萌创星球”想访问你的相机",
  569. describe: "萌创星球想访问您的摄像头,便于拍摄获取图片来替换头像图片"
  570. });
  571. return hasPermission;
  572. },
  573. async checkPhotoLibraryPermission() {
  574. const hasPermission = await permission.request(permission.PermissionType.PHOTO_LIBRARY, {
  575. title: "“萌创星球”想访问你的照片图库",
  576. describe: "萌创星球想访问您本地照片图库,便于获取图片来替换头像图片"
  577. });
  578. return hasPermission;
  579. },
  580. uploadImage(tempFilePath) {
  581. const _self = this;
  582. const uploadTask = uni.uploadFile({
  583. url: _self.$apiHost + '/Xweb/upload_img?skey=' + _self.skey,
  584. filePath: tempFilePath,
  585. name: 'file',
  586. success: function(uploadFileRes) {
  587. let resdata = JSON.parse(uploadFileRes.data);
  588. console.log('Success:', uploadFileRes);
  589. console.log('Upload data:', resdata);
  590. if (resdata.success == 'yes') {
  591. _self.showRights = false;
  592. _self.userInfo.avatar = resdata.url;
  593. uni.showToast({
  594. title: '头像上传成功',
  595. icon: 'success',
  596. duration: 1500
  597. });
  598. } else {
  599. uni.showToast({
  600. title: resdata.msg || '上传失败',
  601. icon: 'none',
  602. duration: 1500
  603. });
  604. }
  605. },
  606. fail: function(uploadFileFail) {
  607. console.error('Error:', uploadFileFail);
  608. uni.showToast({
  609. title: '上传失败,请重试',
  610. icon: 'none',
  611. duration: 1500
  612. });
  613. },
  614. complete: () => {
  615. console.log('Upload complete');
  616. }
  617. });
  618. // 显示上传进度
  619. uploadTask.onProgressUpdate((res) => {
  620. console.log('上传进度' + res.progress);
  621. console.log('已经上传的数据长度' + res.totalBytesSent);
  622. console.log('预期需要上传的数据总长度' + res.totalBytesExpectedToSend);
  623. });
  624. },
  625. toggleInterest(id) {
  626. if (this.selectedInterests.includes(id)) {
  627. // 取消选择
  628. this.selectedInterests.splice(this.selectedInterests.indexOf(id), 1);
  629. } else if (!this.isMaxSelected) {
  630. // 添加选择
  631. this.selectedInterests.push(id);
  632. } else {
  633. uni.showToast({
  634. title: "最多只能选择5个标签哦",
  635. icon: "none",
  636. duration: 1500,
  637. });
  638. }
  639. },
  640. removeTag(tag) {
  641. if (tag.isPreset) {
  642. const index = this.selectedInterests.indexOf(tag.id);
  643. if (index !== -1) {
  644. this.selectedInterests.splice(index, 1);
  645. }
  646. } else {
  647. const index = this.customTags.findIndex(
  648. (item) => item.name === tag.name
  649. );
  650. if (index !== -1) {
  651. this.customTags.splice(index, 1);
  652. }
  653. }
  654. uni.showToast({
  655. title: "已删除",
  656. icon: "none",
  657. duration: 1500,
  658. });
  659. },
  660. showPopup() {
  661. this.$refs.addTagPopup.open();
  662. },
  663. closePopup() {
  664. this.$refs.addTagPopup.close();
  665. this.newTag = "";
  666. },
  667. addNewTag() {
  668. const tagName = this.newTag.trim();
  669. if (!tagName) {
  670. uni.showToast({
  671. title: "请输入标签内容",
  672. icon: "none",
  673. });
  674. return;
  675. }
  676. if (tagName.length > 5) {
  677. uni.showToast({
  678. title: "标签最多5个字哦",
  679. icon: "none",
  680. });
  681. return;
  682. }
  683. if (this.isMaxSelected) {
  684. uni.showToast({
  685. title: "最多只能添加5个标签哦",
  686. icon: "none",
  687. });
  688. return;
  689. }
  690. const isPresetDuplicate = this.interests.some(
  691. (interest) => interest.name === tagName
  692. );
  693. const isCustomDuplicate = this.customTags.some(
  694. (tag) => tag.name === tagName
  695. );
  696. if (isPresetDuplicate || isCustomDuplicate) {
  697. uni.showToast({
  698. title: "这个标签已经添加过啦",
  699. icon: "none",
  700. });
  701. return;
  702. }
  703. this.customTags.push({
  704. name: tagName,
  705. isCustom: true,
  706. });
  707. uni.showToast({
  708. title: "添加成功",
  709. icon: "success",
  710. duration: 1500,
  711. });
  712. this.newTag = "";
  713. this.closePopup();
  714. },
  715. generateRandomNickname() {
  716. const characters = "0123456789";
  717. let result = "织梦者_";
  718. for (let i = 0; i < 8; i++) {
  719. result += characters.charAt(
  720. Math.floor(Math.random() * characters.length)
  721. );
  722. }
  723. this.userInfo.nickname = result;
  724. },
  725. openCalendar() {
  726. this.$refs.calendar.open();
  727. },
  728. confirmBirthday(e) {
  729. this.userInfo.birthday = e.fulldate;
  730. this.userInfo.xinzuo = this.getConstellation(this.userInfo.birthday);
  731. },
  732. getConstellation(birthday) {
  733. if (!birthday) return '';
  734. const month = parseInt(birthday.split('-')[1]);
  735. const day = parseInt(birthday.split('-')[2]);
  736. const constellationDates = [
  737. [1, 20, "水瓶座"],
  738. [2, 19, "双鱼座"],
  739. [3, 21, "白羊座"],
  740. [4, 20, "金牛座"],
  741. [5, 21, "双子座"],
  742. [6, 22, "巨蟹座"],
  743. [7, 23, "狮子座"],
  744. [8, 23, "处女座"],
  745. [9, 23, "天秤座"],
  746. [10, 24, "天蝎座"],
  747. [11, 23, "射手座"],
  748. [12, 22, "摩羯座"]
  749. ];
  750. let constellation = "";
  751. if (day < constellationDates[month - 1][1]) {
  752. constellation = constellationDates[month - 1][2];
  753. } else {
  754. constellation = constellationDates[month % 12][2];
  755. }
  756. return constellation;
  757. },
  758. getCircleStyle(index) {
  759. const {
  760. size,
  761. gap,
  762. rowGap,
  763. rows,
  764. baseTop,
  765. offsetLefts,
  766. offsetTops,
  767. baseLeft,
  768. } = this.circleConfig;
  769. const row = index % rows;
  770. const column = Math.floor(index / rows);
  771. let offsetLeft = 0;
  772. let offsetTop = 0;
  773. if (row % 2 == 0) {
  774. offsetLeft = offsetLefts;
  775. } else {
  776. offsetLeft = -offsetLefts;
  777. }
  778. if (column % 2 == 1) {
  779. offsetTop = offsetTops;
  780. } else {
  781. offsetTop = -offsetTops;
  782. }
  783. const left = baseLeft + column * (size + gap) + offsetLeft + "rpx";
  784. const top = baseTop + row * (size + rowGap) + offsetTop + "rpx";
  785. return {
  786. position: "absolute",
  787. left,
  788. top,
  789. width: size + "rpx",
  790. height: size + "rpx",
  791. };
  792. },
  793. getContainerStyle() {
  794. return {
  795. width: this.totalWidth,
  796. height: "648rpx",
  797. position: "relative",
  798. };
  799. },
  800. handleTouchStart(e) {
  801. this.touchStartX = e.touches[0].clientX;
  802. this.touchStartScrollLeft = e.currentTarget.scrollLeft;
  803. },
  804. handleTouchMove(e) {
  805. if (!this.touchStartX) return;
  806. const deltaX = this.touchStartX - e.touches[0].clientX;
  807. e.currentTarget.scrollLeft = this.touchStartScrollLeft + deltaX;
  808. },
  809. handleTouchEnd() {
  810. this.touchStartX = null;
  811. this.touchStartScrollLeft = null;
  812. },
  813. handleNext() {
  814. if (this.currentStep === 1) {
  815. // 验证第一步数据
  816. if (!this.userInfo.nickname) {
  817. uni.showToast({
  818. title: "请输入昵称",
  819. icon: "none",
  820. });
  821. return;
  822. }
  823. if (!this.userInfo.gender) {
  824. uni.showToast({
  825. title: "请选择性别",
  826. icon: "none",
  827. });
  828. return;
  829. }
  830. this.currentStep = 2;
  831. } else {
  832. // 验证第二步数据
  833. if (
  834. this.selectedInterests.length === 0 &&
  835. this.selectedTags.length === 0
  836. ) {
  837. uni.showToast({
  838. title: "请至少选择一个兴趣",
  839. icon: "none",
  840. });
  841. return;
  842. }
  843. // 提交所有数据
  844. this.submitUserInfo();
  845. }
  846. },
  847. onScroll(e) {
  848. this.scrollTop = e.detail.scrollTop;
  849. },
  850. },
  851. };
  852. </script>
  853. <style lang="scss">
  854. .reserveASeat {
  855. width: 100%;
  856. height: calc(var(--status-bar-height) + 20rpx);
  857. }
  858. .popSel {
  859. position: fixed;
  860. z-index: 101;
  861. top: 0;
  862. left: 0;
  863. background-color: #f2f6f2;
  864. width: 100%;
  865. height: 100vh;
  866. overflow-y: scroll;
  867. -webkit-overflow-scrolling: touch;
  868. box-sizing: border-box;
  869. padding-bottom: 100rpx;
  870. }
  871. .tag_all_select {
  872. padding: 20rpx;
  873. height: 100%;
  874. overflow-y: auto;
  875. .tag_items {
  876. display: flex;
  877. flex-wrap: wrap;
  878. gap: 30rpx;
  879. justify-content: center;
  880. align-items: center;
  881. padding-bottom: 50rpx;
  882. .tag_item {
  883. display: flex;
  884. align-items: center;
  885. justify-content: center;
  886. border-radius: 50%;
  887. background: rgba(255, 255, 255, 0.1);
  888. color: #333;
  889. font-size: 26rpx;
  890. transition: all 0.3s ease;
  891. cursor: pointer;
  892. &.small {
  893. width: 120rpx;
  894. height: 120rpx;
  895. }
  896. &.medium {
  897. width: 160rpx;
  898. height: 160rpx;
  899. font-size: 28rpx;
  900. }
  901. &.large {
  902. width: 200rpx;
  903. height: 200rpx;
  904. font-size: 32rpx;
  905. }
  906. &.active {
  907. transform: scale(1.2);
  908. background: rgba(255, 255, 255, 0.2);
  909. box-shadow: 0 0 20rpx rgba(255, 255, 255, 0.3);
  910. z-index: 1;
  911. }
  912. &:not(.active):hover {
  913. transform: scale(1.05);
  914. }
  915. }
  916. }
  917. }
  918. .step-container {
  919. min-height: 100vh;
  920. background: url("../../static/me/step/wd_bg_bianjiziliao.png") top center/100% no-repeat,
  921. #f2f6f2;
  922. padding: 40rpx 0;
  923. padding-bottom: 230rpx;
  924. box-sizing: border-box;
  925. }
  926. .step-header {
  927. margin-bottom: 20rpx;
  928. padding: 0 40rpx;
  929. .step-number {
  930. font-size: 48rpx;
  931. font-weight: bold;
  932. color: #000;
  933. margin-bottom: 20rpx;
  934. display: block;
  935. text-align: center;
  936. }
  937. .progress-container {
  938. height: 6rpx;
  939. background: #f1f1f1;
  940. border-radius: 4rpx;
  941. overflow: hidden;
  942. .progress-inner {
  943. height: 100%;
  944. background: #1f1f1f;
  945. border-radius: 4rpx;
  946. transition: width 0.3s ease;
  947. height: 6rpx;
  948. }
  949. }
  950. }
  951. .step-content {
  952. padding: 0 40rpx;
  953. .step-title {
  954. text-align: center;
  955. font-size: 32rpx;
  956. font-weight: bold;
  957. color: #666;
  958. margin-bottom: 50rpx;
  959. letter-spacing: 1rpx;
  960. text {
  961. font-size: 40rpx;
  962. }
  963. }
  964. }
  965. .avatar-section {
  966. display: flex;
  967. justify-content: center;
  968. margin-bottom: 60rpx;
  969. .avatar-wrapper {
  970. width: 200rpx;
  971. height: 200rpx;
  972. border-radius: 50%;
  973. background: #f8f8f8;
  974. display: flex;
  975. align-items: center;
  976. justify-content: center;
  977. border: 4rpx dashed #e5e5e5;
  978. position: relative;
  979. .avatar {
  980. width: 100%;
  981. height: 100%;
  982. }
  983. .avatar-placeholder {
  984. width: 64rpx;
  985. height: 64rpx;
  986. position: absolute;
  987. bottom: 0;
  988. right: 0;
  989. .camera-icon {
  990. width: 100%;
  991. height: 100%;
  992. }
  993. }
  994. }
  995. }
  996. .input-section {
  997. margin-bottom: 20rpx;
  998. .input-wrapper {
  999. position: relative;
  1000. display: flex;
  1001. align-items: center;
  1002. background: #f8f8f8;
  1003. border-radius: 16rpx;
  1004. padding-right: 20rpx;
  1005. input {
  1006. flex: 1;
  1007. height: 88rpx;
  1008. padding: 0 20rpx 0 30rpx;
  1009. font-size: 28rpx;
  1010. color: #333;
  1011. background: transparent;
  1012. &::placeholder {
  1013. color: #999;
  1014. }
  1015. }
  1016. .input-actions {
  1017. display: flex;
  1018. align-items: center;
  1019. gap: 16rpx;
  1020. .close-icon {
  1021. width: 36rpx;
  1022. height: 36rpx;
  1023. }
  1024. .random {
  1025. width: 44rpx;
  1026. height: 44rpx;
  1027. }
  1028. }
  1029. }
  1030. }
  1031. .gender-section {
  1032. margin-bottom: 20rpx;
  1033. .gender-options {
  1034. display: flex;
  1035. gap: 20rpx;
  1036. .gender-item {
  1037. flex: 1;
  1038. background: #f8f8f8;
  1039. border-radius: 20rpx;
  1040. display: flex;
  1041. flex-direction: column;
  1042. align-items: center;
  1043. justify-content: center;
  1044. transition: all 0.3s ease;
  1045. width: 184px;
  1046. height: 168rpx;
  1047. border-radius: 20rpx;
  1048. border: 4rpx solid #e9e9e9;
  1049. &.active {
  1050. background: linear-gradient(180deg,
  1051. #f0ffd9 0%,
  1052. rgba(240, 255, 217, 0) 99%);
  1053. transform: scale(1.02);
  1054. border-color: #1f1f1f;
  1055. }
  1056. .gender-icon {
  1057. width: 80rpx;
  1058. height: 80rpx;
  1059. margin-bottom: 16rpx;
  1060. }
  1061. text {
  1062. font-size: 28rpx;
  1063. color: #333;
  1064. }
  1065. }
  1066. }
  1067. }
  1068. .birthday-section {
  1069. margin-bottom: 20rpx;
  1070. background: #fff;
  1071. padding: 20rpx;
  1072. border-radius: 20rpx;
  1073. .input-label {
  1074. font-size: 28rpx;
  1075. color: #333;
  1076. padding-bottom: 20rpx;
  1077. }
  1078. .birthday-picker {
  1079. height: 88rpx;
  1080. background: #f8f8f8;
  1081. border-radius: 16rpx;
  1082. padding: 0 30rpx;
  1083. display: flex;
  1084. align-items: center;
  1085. justify-content: space-between;
  1086. picker {
  1087. flex: 1;
  1088. height: 100%;
  1089. .uni-input {
  1090. width: 100%;
  1091. height: 100%;
  1092. display: flex;
  1093. align-items: center;
  1094. gap: 12rpx;
  1095. text {
  1096. font-size: 28rpx;
  1097. color: #333;
  1098. &.placeholder {
  1099. color: #999;
  1100. }
  1101. &.constellation {
  1102. font-size: 28rpx;
  1103. color: #1f1f1f;
  1104. padding: 4rpx 12rpx;
  1105. border-radius: 8rpx;
  1106. }
  1107. }
  1108. }
  1109. }
  1110. .arrow-icon {
  1111. width: 32rpx;
  1112. height: 32rpx;
  1113. flex-shrink: 0;
  1114. }
  1115. }
  1116. }
  1117. .interest-section {
  1118. .interest-tip {
  1119. font-size: 28rpx;
  1120. color: #666;
  1121. margin-bottom: 30rpx;
  1122. }
  1123. .interest-circles {
  1124. width: 100%;
  1125. height: 648rpx;
  1126. overflow-x: scroll;
  1127. overflow-y: hidden;
  1128. position: relative;
  1129. margin-bottom: 60rpx;
  1130. padding: 10rpx;
  1131. box-sizing: border-box;
  1132. -webkit-overflow-scrolling: touch;
  1133. &::-webkit-scrollbar {
  1134. display: none;
  1135. }
  1136. -ms-overflow-style: none;
  1137. scrollbar-width: none;
  1138. .interest-circles-container {
  1139. position: relative;
  1140. height: 100%;
  1141. display: flex;
  1142. flex-wrap: wrap;
  1143. gap: 20rpx;
  1144. padding: 20rpx;
  1145. }
  1146. .interest-circle-box {
  1147. width: 132rpx;
  1148. height: 132rpx;
  1149. border-radius: 50%;
  1150. position: relative;
  1151. display: flex;
  1152. align-items: center;
  1153. justify-content: center;
  1154. &.active {
  1155. background: url("../../static/me/step/dlzc_btn_xuanzhong.png") no-repeat center center / 100% 100%;
  1156. }
  1157. &.disabled {
  1158. opacity: 0.5;
  1159. cursor: not-allowed;
  1160. .interest-circle {
  1161. background: rgba(0, 0, 0, 0.02);
  1162. }
  1163. }
  1164. .interest-circle {
  1165. width: 120rpx;
  1166. height: 120rpx;
  1167. display: flex;
  1168. align-items: center;
  1169. justify-content: center;
  1170. border-radius: 50%;
  1171. background: rgba(0, 0, 0, 0.04);
  1172. font-size: 24rpx;
  1173. color: #666;
  1174. transition: all 0.3s ease;
  1175. text-align: center;
  1176. box-sizing: border-box;
  1177. max-width: 120rpx;
  1178. padding: 10rpx;
  1179. >view {
  1180. width: 100%;
  1181. white-space: nowrap;
  1182. overflow: hidden;
  1183. text-overflow: ellipsis;
  1184. }
  1185. }
  1186. }
  1187. }
  1188. }
  1189. .interest-tags {
  1190. display: flex;
  1191. flex-wrap: wrap;
  1192. gap: 20rpx;
  1193. margin-top: 30rpx;
  1194. padding: 0 20rpx;
  1195. .interest-tag {
  1196. padding: 16rpx 24rpx;
  1197. background: #ffffff;
  1198. border-radius: 100rpx;
  1199. font-size: 28rpx;
  1200. color: #333333;
  1201. display: flex;
  1202. align-items: center;
  1203. box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.05);
  1204. position: relative;
  1205. .remove-tag {
  1206. margin-left: 12rpx;
  1207. font-size: 32rpx;
  1208. color: #333333;
  1209. padding: 0 6rpx;
  1210. display: flex;
  1211. align-items: center;
  1212. position: relative;
  1213. z-index: 1;
  1214. &::after {
  1215. content: "";
  1216. position: absolute;
  1217. left: -8rpx;
  1218. right: -8rpx;
  1219. top: -8rpx;
  1220. bottom: -8rpx;
  1221. z-index: 0;
  1222. }
  1223. }
  1224. }
  1225. .add-tag {
  1226. padding: 16rpx 24rpx;
  1227. background: #ffffff;
  1228. border-radius: 100rpx;
  1229. font-size: 28rpx;
  1230. color: #333333;
  1231. display: flex;
  1232. align-items: center;
  1233. box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.05);
  1234. .add-icon {
  1235. width: 32rpx;
  1236. height: 32rpx;
  1237. margin-right: 12rpx;
  1238. }
  1239. }
  1240. }
  1241. .bottom-button {
  1242. position: fixed;
  1243. left: 40rpx;
  1244. right: 40rpx;
  1245. bottom: 40rpx;
  1246. height: 88rpx;
  1247. background: #000;
  1248. border-radius: 44rpx;
  1249. color: #fff;
  1250. font-size: 32rpx;
  1251. display: flex;
  1252. align-items: center;
  1253. justify-content: center;
  1254. transition: all 0.3s ease;
  1255. &.step2 {
  1256. background: linear-gradient(90deg, #acf934 0%, #23c343 100%);
  1257. color: #000;
  1258. }
  1259. }
  1260. .add-tag-popup {
  1261. background: #ffffff;
  1262. border-radius: 24rpx;
  1263. width: 580rpx;
  1264. height: 70vh;
  1265. max-height: 800rpx;
  1266. display: flex;
  1267. flex-direction: column;
  1268. .popup-title {
  1269. padding: 40rpx 30rpx 20rpx;
  1270. font-size: 32rpx;
  1271. color: #333333;
  1272. text-align: center;
  1273. font-weight: 600;
  1274. flex-shrink: 0;
  1275. }
  1276. .popup-content {
  1277. flex: 1;
  1278. overflow-y: auto;
  1279. padding: 0 30rpx;
  1280. margin-bottom: 20rpx;
  1281. .popup-input {
  1282. margin-bottom: 30rpx;
  1283. .tag-input {
  1284. width: 100%;
  1285. height: 80rpx;
  1286. background: #f2f6f2;
  1287. border-radius: 12rpx;
  1288. padding: 0 24rpx;
  1289. font-size: 28rpx;
  1290. color: #333333;
  1291. &.disabled {
  1292. background: rgba(0, 0, 0, 0.02);
  1293. color: #999;
  1294. }
  1295. }
  1296. }
  1297. .selected-tags {
  1298. .selected-tags-title {
  1299. font-size: 28rpx;
  1300. color: #666666;
  1301. margin-bottom: 20rpx;
  1302. display: flex;
  1303. align-items: center;
  1304. justify-content: space-between;
  1305. .max-hint {
  1306. font-size: 24rpx;
  1307. color: #ff6b6b;
  1308. }
  1309. }
  1310. .selected-tags-list {
  1311. display: flex;
  1312. flex-wrap: wrap;
  1313. gap: 16rpx;
  1314. .selected-tag {
  1315. padding: 12rpx 24rpx;
  1316. background: #f2f6f2;
  1317. border-radius: 100rpx;
  1318. font-size: 26rpx;
  1319. color: #333333;
  1320. }
  1321. }
  1322. }
  1323. }
  1324. .popup-buttons {
  1325. padding: 20rpx 30rpx 30rpx;
  1326. display: flex;
  1327. gap: 20rpx;
  1328. background: #ffffff;
  1329. flex-shrink: 0;
  1330. position: relative;
  1331. &::before {
  1332. content: "";
  1333. position: absolute;
  1334. left: 0;
  1335. right: 0;
  1336. top: -20rpx;
  1337. height: 20rpx;
  1338. background: linear-gradient(to top,
  1339. rgba(255, 255, 255, 1),
  1340. rgba(255, 255, 255, 0));
  1341. }
  1342. button {
  1343. flex: 1;
  1344. height: 80rpx;
  1345. border-radius: 12rpx;
  1346. font-size: 28rpx;
  1347. display: flex;
  1348. align-items: center;
  1349. justify-content: center;
  1350. border: none;
  1351. &.btn-cancel {
  1352. background: #ffffff;
  1353. color: #333333;
  1354. border: 2rpx solid #1f1f1f;
  1355. }
  1356. &.btn-confirm {
  1357. background: #333333;
  1358. color: #ffffff;
  1359. &.disabled {
  1360. opacity: 0.5;
  1361. background: #999;
  1362. }
  1363. }
  1364. }
  1365. }
  1366. }
  1367. .birthday-section,
  1368. .input-section,
  1369. .gender-section {
  1370. background: #fff;
  1371. padding: 20rpx;
  1372. border-radius: 20rpx;
  1373. .input-label {
  1374. font-size: 28rpx;
  1375. color: #333;
  1376. padding-bottom: 20rpx;
  1377. }
  1378. }
  1379. </style>