step.vue 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506
  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. },
  731. getConstellation(birthday) {
  732. if (!birthday) return '';
  733. const month = parseInt(birthday.split('-')[1]);
  734. const day = parseInt(birthday.split('-')[2]);
  735. const constellationDates = [
  736. [1, 20, "水瓶座"],
  737. [2, 19, "双鱼座"],
  738. [3, 21, "白羊座"],
  739. [4, 20, "金牛座"],
  740. [5, 21, "双子座"],
  741. [6, 22, "巨蟹座"],
  742. [7, 23, "狮子座"],
  743. [8, 23, "处女座"],
  744. [9, 23, "天秤座"],
  745. [10, 24, "天蝎座"],
  746. [11, 23, "射手座"],
  747. [12, 22, "摩羯座"]
  748. ];
  749. let constellation = "";
  750. if (day < constellationDates[month - 1][1]) {
  751. constellation = constellationDates[month - 1][2];
  752. } else {
  753. constellation = constellationDates[month % 12][2];
  754. }
  755. return constellation;
  756. },
  757. getCircleStyle(index) {
  758. const {
  759. size,
  760. gap,
  761. rowGap,
  762. rows,
  763. baseTop,
  764. offsetLefts,
  765. offsetTops,
  766. baseLeft,
  767. } = this.circleConfig;
  768. const row = index % rows;
  769. const column = Math.floor(index / rows);
  770. let offsetLeft = 0;
  771. let offsetTop = 0;
  772. if (row % 2 == 0) {
  773. offsetLeft = offsetLefts;
  774. } else {
  775. offsetLeft = -offsetLefts;
  776. }
  777. if (column % 2 == 1) {
  778. offsetTop = offsetTops;
  779. } else {
  780. offsetTop = -offsetTops;
  781. }
  782. const left = baseLeft + column * (size + gap) + offsetLeft + "rpx";
  783. const top = baseTop + row * (size + rowGap) + offsetTop + "rpx";
  784. return {
  785. position: "absolute",
  786. left,
  787. top,
  788. width: size + "rpx",
  789. height: size + "rpx",
  790. };
  791. },
  792. getContainerStyle() {
  793. return {
  794. width: this.totalWidth,
  795. height: "648rpx",
  796. position: "relative",
  797. };
  798. },
  799. handleTouchStart(e) {
  800. this.touchStartX = e.touches[0].clientX;
  801. this.touchStartScrollLeft = e.currentTarget.scrollLeft;
  802. },
  803. handleTouchMove(e) {
  804. if (!this.touchStartX) return;
  805. const deltaX = this.touchStartX - e.touches[0].clientX;
  806. e.currentTarget.scrollLeft = this.touchStartScrollLeft + deltaX;
  807. },
  808. handleTouchEnd() {
  809. this.touchStartX = null;
  810. this.touchStartScrollLeft = null;
  811. },
  812. handleNext() {
  813. if (this.currentStep === 1) {
  814. // 验证第一步数据
  815. if (!this.userInfo.nickname) {
  816. uni.showToast({
  817. title: "请输入昵称",
  818. icon: "none",
  819. });
  820. return;
  821. }
  822. if (!this.userInfo.gender) {
  823. uni.showToast({
  824. title: "请选择性别",
  825. icon: "none",
  826. });
  827. return;
  828. }
  829. this.currentStep = 2;
  830. } else {
  831. // 验证第二步数据
  832. if (
  833. this.selectedInterests.length === 0 &&
  834. this.selectedTags.length === 0
  835. ) {
  836. uni.showToast({
  837. title: "请至少选择一个兴趣",
  838. icon: "none",
  839. });
  840. return;
  841. }
  842. // 提交所有数据
  843. this.submitUserInfo();
  844. }
  845. },
  846. onScroll(e) {
  847. this.scrollTop = e.detail.scrollTop;
  848. },
  849. },
  850. };
  851. </script>
  852. <style lang="scss">
  853. .reserveASeat {
  854. width: 100%;
  855. height: calc(var(--status-bar-height) + 20rpx);
  856. }
  857. .popSel {
  858. position: fixed;
  859. z-index: 101;
  860. top: 0;
  861. left: 0;
  862. background-color: #f2f6f2;
  863. width: 100%;
  864. height: 100vh;
  865. overflow-y: scroll;
  866. -webkit-overflow-scrolling: touch;
  867. box-sizing: border-box;
  868. padding-bottom: 100rpx;
  869. }
  870. .tag_all_select {
  871. padding: 20rpx;
  872. height: 100%;
  873. overflow-y: auto;
  874. .tag_items {
  875. display: flex;
  876. flex-wrap: wrap;
  877. gap: 30rpx;
  878. justify-content: center;
  879. align-items: center;
  880. padding-bottom: 50rpx;
  881. .tag_item {
  882. display: flex;
  883. align-items: center;
  884. justify-content: center;
  885. border-radius: 50%;
  886. background: rgba(255, 255, 255, 0.1);
  887. color: #333;
  888. font-size: 26rpx;
  889. transition: all 0.3s ease;
  890. cursor: pointer;
  891. &.small {
  892. width: 120rpx;
  893. height: 120rpx;
  894. }
  895. &.medium {
  896. width: 160rpx;
  897. height: 160rpx;
  898. font-size: 28rpx;
  899. }
  900. &.large {
  901. width: 200rpx;
  902. height: 200rpx;
  903. font-size: 32rpx;
  904. }
  905. &.active {
  906. transform: scale(1.2);
  907. background: rgba(255, 255, 255, 0.2);
  908. box-shadow: 0 0 20rpx rgba(255, 255, 255, 0.3);
  909. z-index: 1;
  910. }
  911. &:not(.active):hover {
  912. transform: scale(1.05);
  913. }
  914. }
  915. }
  916. }
  917. .step-container {
  918. min-height: 100vh;
  919. background: url("../../static/me/step/wd_bg_bianjiziliao.png") top center/100% no-repeat,
  920. #f2f6f2;
  921. padding: 40rpx 0;
  922. padding-bottom: 230rpx;
  923. box-sizing: border-box;
  924. }
  925. .step-header {
  926. margin-bottom: 20rpx;
  927. padding: 0 40rpx;
  928. .step-number {
  929. font-size: 48rpx;
  930. font-weight: bold;
  931. color: #000;
  932. margin-bottom: 20rpx;
  933. display: block;
  934. text-align: center;
  935. }
  936. .progress-container {
  937. height: 6rpx;
  938. background: #f1f1f1;
  939. border-radius: 4rpx;
  940. overflow: hidden;
  941. .progress-inner {
  942. height: 100%;
  943. background: #1f1f1f;
  944. border-radius: 4rpx;
  945. transition: width 0.3s ease;
  946. height: 6rpx;
  947. }
  948. }
  949. }
  950. .step-content {
  951. padding: 0 40rpx;
  952. .step-title {
  953. text-align: center;
  954. font-size: 32rpx;
  955. font-weight: bold;
  956. color: #666;
  957. margin-bottom: 50rpx;
  958. letter-spacing: 1rpx;
  959. text {
  960. font-size: 40rpx;
  961. }
  962. }
  963. }
  964. .avatar-section {
  965. display: flex;
  966. justify-content: center;
  967. margin-bottom: 60rpx;
  968. .avatar-wrapper {
  969. width: 200rpx;
  970. height: 200rpx;
  971. border-radius: 50%;
  972. background: #f8f8f8;
  973. display: flex;
  974. align-items: center;
  975. justify-content: center;
  976. border: 4rpx dashed #e5e5e5;
  977. position: relative;
  978. .avatar {
  979. width: 100%;
  980. height: 100%;
  981. }
  982. .avatar-placeholder {
  983. width: 64rpx;
  984. height: 64rpx;
  985. position: absolute;
  986. bottom: 0;
  987. right: 0;
  988. .camera-icon {
  989. width: 100%;
  990. height: 100%;
  991. }
  992. }
  993. }
  994. }
  995. .input-section {
  996. margin-bottom: 20rpx;
  997. .input-wrapper {
  998. position: relative;
  999. display: flex;
  1000. align-items: center;
  1001. background: #f8f8f8;
  1002. border-radius: 16rpx;
  1003. padding-right: 20rpx;
  1004. input {
  1005. flex: 1;
  1006. height: 88rpx;
  1007. padding: 0 20rpx 0 30rpx;
  1008. font-size: 28rpx;
  1009. color: #333;
  1010. background: transparent;
  1011. &::placeholder {
  1012. color: #999;
  1013. }
  1014. }
  1015. .input-actions {
  1016. display: flex;
  1017. align-items: center;
  1018. gap: 16rpx;
  1019. .close-icon {
  1020. width: 36rpx;
  1021. height: 36rpx;
  1022. }
  1023. .random {
  1024. width: 44rpx;
  1025. height: 44rpx;
  1026. }
  1027. }
  1028. }
  1029. }
  1030. .gender-section {
  1031. margin-bottom: 20rpx;
  1032. .gender-options {
  1033. display: flex;
  1034. gap: 20rpx;
  1035. .gender-item {
  1036. flex: 1;
  1037. background: #f8f8f8;
  1038. border-radius: 20rpx;
  1039. display: flex;
  1040. flex-direction: column;
  1041. align-items: center;
  1042. justify-content: center;
  1043. transition: all 0.3s ease;
  1044. width: 184px;
  1045. height: 168rpx;
  1046. border-radius: 20rpx;
  1047. border: 4rpx solid #e9e9e9;
  1048. &.active {
  1049. background: linear-gradient(180deg,
  1050. #f0ffd9 0%,
  1051. rgba(240, 255, 217, 0) 99%);
  1052. transform: scale(1.02);
  1053. border-color: #1f1f1f;
  1054. }
  1055. .gender-icon {
  1056. width: 80rpx;
  1057. height: 80rpx;
  1058. margin-bottom: 16rpx;
  1059. }
  1060. text {
  1061. font-size: 28rpx;
  1062. color: #333;
  1063. }
  1064. }
  1065. }
  1066. }
  1067. .birthday-section {
  1068. margin-bottom: 20rpx;
  1069. background: #fff;
  1070. padding: 20rpx;
  1071. border-radius: 20rpx;
  1072. .input-label {
  1073. font-size: 28rpx;
  1074. color: #333;
  1075. padding-bottom: 20rpx;
  1076. }
  1077. .birthday-picker {
  1078. height: 88rpx;
  1079. background: #f8f8f8;
  1080. border-radius: 16rpx;
  1081. padding: 0 30rpx;
  1082. display: flex;
  1083. align-items: center;
  1084. justify-content: space-between;
  1085. picker {
  1086. flex: 1;
  1087. height: 100%;
  1088. .uni-input {
  1089. width: 100%;
  1090. height: 100%;
  1091. display: flex;
  1092. align-items: center;
  1093. gap: 12rpx;
  1094. text {
  1095. font-size: 28rpx;
  1096. color: #333;
  1097. &.placeholder {
  1098. color: #999;
  1099. }
  1100. &.constellation {
  1101. font-size: 28rpx;
  1102. color: #1f1f1f;
  1103. padding: 4rpx 12rpx;
  1104. border-radius: 8rpx;
  1105. }
  1106. }
  1107. }
  1108. }
  1109. .arrow-icon {
  1110. width: 32rpx;
  1111. height: 32rpx;
  1112. flex-shrink: 0;
  1113. }
  1114. }
  1115. }
  1116. .interest-section {
  1117. .interest-tip {
  1118. font-size: 28rpx;
  1119. color: #666;
  1120. margin-bottom: 30rpx;
  1121. }
  1122. .interest-circles {
  1123. width: 100%;
  1124. height: 648rpx;
  1125. overflow-x: scroll;
  1126. overflow-y: hidden;
  1127. position: relative;
  1128. margin-bottom: 60rpx;
  1129. padding: 10rpx;
  1130. box-sizing: border-box;
  1131. -webkit-overflow-scrolling: touch;
  1132. &::-webkit-scrollbar {
  1133. display: none;
  1134. }
  1135. -ms-overflow-style: none;
  1136. scrollbar-width: none;
  1137. .interest-circles-container {
  1138. position: relative;
  1139. height: 100%;
  1140. display: flex;
  1141. flex-wrap: wrap;
  1142. gap: 20rpx;
  1143. padding: 20rpx;
  1144. }
  1145. .interest-circle-box {
  1146. width: 132rpx;
  1147. height: 132rpx;
  1148. border-radius: 50%;
  1149. position: relative;
  1150. display: flex;
  1151. align-items: center;
  1152. justify-content: center;
  1153. &.active {
  1154. background: url("../../static/me/step/dlzc_btn_xuanzhong.png") no-repeat center center / 100% 100%;
  1155. }
  1156. &.disabled {
  1157. opacity: 0.5;
  1158. cursor: not-allowed;
  1159. .interest-circle {
  1160. background: rgba(0, 0, 0, 0.02);
  1161. }
  1162. }
  1163. .interest-circle {
  1164. width: 120rpx;
  1165. height: 120rpx;
  1166. display: flex;
  1167. align-items: center;
  1168. justify-content: center;
  1169. border-radius: 50%;
  1170. background: rgba(0, 0, 0, 0.04);
  1171. font-size: 24rpx;
  1172. color: #666;
  1173. transition: all 0.3s ease;
  1174. text-align: center;
  1175. box-sizing: border-box;
  1176. max-width: 120rpx;
  1177. padding: 10rpx;
  1178. >view {
  1179. width: 100%;
  1180. white-space: nowrap;
  1181. overflow: hidden;
  1182. text-overflow: ellipsis;
  1183. }
  1184. }
  1185. }
  1186. }
  1187. }
  1188. .interest-tags {
  1189. display: flex;
  1190. flex-wrap: wrap;
  1191. gap: 20rpx;
  1192. margin-top: 30rpx;
  1193. padding: 0 20rpx;
  1194. .interest-tag {
  1195. padding: 16rpx 24rpx;
  1196. background: #ffffff;
  1197. border-radius: 100rpx;
  1198. font-size: 28rpx;
  1199. color: #333333;
  1200. display: flex;
  1201. align-items: center;
  1202. box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.05);
  1203. position: relative;
  1204. .remove-tag {
  1205. margin-left: 12rpx;
  1206. font-size: 32rpx;
  1207. color: #333333;
  1208. padding: 0 6rpx;
  1209. display: flex;
  1210. align-items: center;
  1211. position: relative;
  1212. z-index: 1;
  1213. &::after {
  1214. content: "";
  1215. position: absolute;
  1216. left: -8rpx;
  1217. right: -8rpx;
  1218. top: -8rpx;
  1219. bottom: -8rpx;
  1220. z-index: 0;
  1221. }
  1222. }
  1223. }
  1224. .add-tag {
  1225. padding: 16rpx 24rpx;
  1226. background: #ffffff;
  1227. border-radius: 100rpx;
  1228. font-size: 28rpx;
  1229. color: #333333;
  1230. display: flex;
  1231. align-items: center;
  1232. box-shadow: 0 4rpx 8rpx rgba(0, 0, 0, 0.05);
  1233. .add-icon {
  1234. width: 32rpx;
  1235. height: 32rpx;
  1236. margin-right: 12rpx;
  1237. }
  1238. }
  1239. }
  1240. .bottom-button {
  1241. position: fixed;
  1242. left: 40rpx;
  1243. right: 40rpx;
  1244. bottom: 40rpx;
  1245. height: 88rpx;
  1246. background: #000;
  1247. border-radius: 44rpx;
  1248. color: #fff;
  1249. font-size: 32rpx;
  1250. display: flex;
  1251. align-items: center;
  1252. justify-content: center;
  1253. transition: all 0.3s ease;
  1254. &.step2 {
  1255. background: linear-gradient(90deg, #acf934 0%, #23c343 100%);
  1256. color: #000;
  1257. }
  1258. }
  1259. .add-tag-popup {
  1260. background: #ffffff;
  1261. border-radius: 24rpx;
  1262. width: 580rpx;
  1263. height: 70vh;
  1264. max-height: 800rpx;
  1265. display: flex;
  1266. flex-direction: column;
  1267. .popup-title {
  1268. padding: 40rpx 30rpx 20rpx;
  1269. font-size: 32rpx;
  1270. color: #333333;
  1271. text-align: center;
  1272. font-weight: 600;
  1273. flex-shrink: 0;
  1274. }
  1275. .popup-content {
  1276. flex: 1;
  1277. overflow-y: auto;
  1278. padding: 0 30rpx;
  1279. margin-bottom: 20rpx;
  1280. .popup-input {
  1281. margin-bottom: 30rpx;
  1282. .tag-input {
  1283. width: 100%;
  1284. height: 80rpx;
  1285. background: #f2f6f2;
  1286. border-radius: 12rpx;
  1287. padding: 0 24rpx;
  1288. font-size: 28rpx;
  1289. color: #333333;
  1290. &.disabled {
  1291. background: rgba(0, 0, 0, 0.02);
  1292. color: #999;
  1293. }
  1294. }
  1295. }
  1296. .selected-tags {
  1297. .selected-tags-title {
  1298. font-size: 28rpx;
  1299. color: #666666;
  1300. margin-bottom: 20rpx;
  1301. display: flex;
  1302. align-items: center;
  1303. justify-content: space-between;
  1304. .max-hint {
  1305. font-size: 24rpx;
  1306. color: #ff6b6b;
  1307. }
  1308. }
  1309. .selected-tags-list {
  1310. display: flex;
  1311. flex-wrap: wrap;
  1312. gap: 16rpx;
  1313. .selected-tag {
  1314. padding: 12rpx 24rpx;
  1315. background: #f2f6f2;
  1316. border-radius: 100rpx;
  1317. font-size: 26rpx;
  1318. color: #333333;
  1319. }
  1320. }
  1321. }
  1322. }
  1323. .popup-buttons {
  1324. padding: 20rpx 30rpx 30rpx;
  1325. display: flex;
  1326. gap: 20rpx;
  1327. background: #ffffff;
  1328. flex-shrink: 0;
  1329. position: relative;
  1330. &::before {
  1331. content: "";
  1332. position: absolute;
  1333. left: 0;
  1334. right: 0;
  1335. top: -20rpx;
  1336. height: 20rpx;
  1337. background: linear-gradient(to top,
  1338. rgba(255, 255, 255, 1),
  1339. rgba(255, 255, 255, 0));
  1340. }
  1341. button {
  1342. flex: 1;
  1343. height: 80rpx;
  1344. border-radius: 12rpx;
  1345. font-size: 28rpx;
  1346. display: flex;
  1347. align-items: center;
  1348. justify-content: center;
  1349. border: none;
  1350. &.btn-cancel {
  1351. background: #ffffff;
  1352. color: #333333;
  1353. border: 2rpx solid #1f1f1f;
  1354. }
  1355. &.btn-confirm {
  1356. background: #333333;
  1357. color: #ffffff;
  1358. &.disabled {
  1359. opacity: 0.5;
  1360. background: #999;
  1361. }
  1362. }
  1363. }
  1364. }
  1365. }
  1366. .birthday-section,
  1367. .input-section,
  1368. .gender-section {
  1369. background: #fff;
  1370. padding: 20rpx;
  1371. border-radius: 20rpx;
  1372. .input-label {
  1373. font-size: 28rpx;
  1374. color: #333;
  1375. padding-bottom: 20rpx;
  1376. }
  1377. }
  1378. </style>