tree.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. <template>
  2. <view class="page-container">
  3. <view class="base-container">
  4. <member-level :treeData="treeData">
  5. <view class="toogle" @click="handleShow">切换 {{name}}<up-icon class="icon" name="arrow-down" color="#fff"
  6. size="12"></up-icon></view>
  7. </member-level>
  8. <view class="tree-cont">
  9. <!-- 弹幕组件 -->
  10. <view class="danmaku-wrapper">
  11. <danmakuManager
  12. ref="danmakuRef"
  13. :danmakuList="danmakuList"
  14. :height="100"
  15. :infinite="true"
  16. :speed="80"
  17. @danmakuComplete="onDanmakuComplete"
  18. ></danmakuManager>
  19. </view>
  20. <view class="dialogue-tips">
  21. <view class="tips-name">
  22. <image class="tip-img" :src="`${config.BASIC_IMG}img/treePage/sun-icon.png`"></image>
  23. <text>亲爱的主人!</text>
  24. </view>
  25. <view class="tips-cont">今天是我开花的日子,我很开心!</view>
  26. </view>
  27. <view class="tree-name">
  28. <view>{{treeName}}</view>
  29. <image v-if="userInfo.tel" @click="handleEditName" class="edit-icon" :src="`${config.BASIC_IMG}img/edit-icon.png`">
  30. </image>
  31. </view>
  32. <image class="drone-icon" :src="`${config.BASIC_IMG}img/treePage/drone-icon.png`"></image>
  33. <view class="tool-wrap">
  34. <view class="tool-left">
  35. <view :class="['tool-item',item.className]" v-for="(item,index) in toolLeftList" :key="index"
  36. @click="handleToolItem(item)">
  37. <image class="icon" :src="`${config.BASIC_IMG}img/treePage/l-tree-icon-${index+1}.png`">
  38. </image>
  39. <view class="name">{{item.name}}</view>
  40. </view>
  41. </view>
  42. <view class="tool-right">
  43. <view :class="['tool-item',item.className]" v-for="(item,index) in toolRightList" :key="index"
  44. @click="handleToolItem(item)">
  45. <image class="icon" :src="`${config.BASIC_IMG}img/treePage/r-tree-icon-${index+1}.png`">
  46. </image>
  47. <view class="name">{{item.name}}</view>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. <view class="tree-footer">
  53. <template v-if="userInfo.tel">
  54. <view class="footer-item" v-for="(item,index) in footerList" :key="index" @click="handleItem(index)">
  55. <view @click="requestSubscribe">
  56. <button class="share-btn" open-type="share" v-if="index === 2">
  57. <image class="icon" :src="`${config.BASIC_IMG}img/treePage/b-tree-icon-${index+1}.png`">
  58. </image>
  59. </button>
  60. <image v-else class="icon" :class="{small:index === 0}" :src="`${config.BASIC_IMG}img/treePage/b-tree-icon-${index+1}.png`">
  61. </image>
  62. <view class="name">{{item}}</view>
  63. </view>
  64. </view>
  65. </template>
  66. <view v-else class="button" @click="handlePage">开启我的守护</view>
  67. </view>
  68. </view>
  69. <!-- 引导弹窗 -->
  70. <view class="guide-bg" v-if="showMask" @click="handleClose">
  71. <image class="guide-icon" :src="`${config.BASIC_IMG}img/treePage/guide-1.png`"></image>
  72. </view>
  73. <!-- 切换 -->
  74. <up-picker :show="showPicker" :columns="columns" :defaultIndex="[0]" @cancel="handleCancel"
  75. @confirm="handleConfirm" keyName="name" valueName="speciesId"></up-picker>
  76. <!-- 签到打卡 -->
  77. <checkinPopup @closedCheckPopup="closedCheckPopup"></checkinPopup>
  78. <!-- 编辑树名称 -->
  79. <editNamePopup ref="editNameRef" @editEnd="getBySampleId"></editNamePopup>
  80. <!-- 海报弹窗 -->
  81. <posterPopup :showPoster="showPoster" :farmBuyId="farmBuyId" :treeName="treeName" :sampleId="sampleId"></posterPopup>
  82. <!-- 果树成功弹窗 -->
  83. <guardSuccessPopup :show="showGuardSuccess" :treeData="treeData"></guardSuccessPopup>
  84. <!-- 果树相册弹窗 -->
  85. <tree-album-popup :show="showAlbum" :farmBuyId="farmBuyId" :sampleId="sampleId"></tree-album-popup>
  86. <!-- 等级升级成功弹窗 -->
  87. <levelSuccessPopup></levelSuccessPopup>
  88. <!-- 祝福弹窗 -->
  89. <blessingsPopup :show="showBlessingsPopup" :showSuccess="showSuccess" :farmBuyId="farmBuyId"
  90. :clockinType="clockinType" @clockinCallback="getBySampleId"></blessingsPopup>
  91. </view>
  92. </template>
  93. <script setup>
  94. import config from "@/api/config.js"
  95. import {
  96. onLoad,
  97. onShareAppMessage,
  98. onShow,
  99. onHide,
  100. onUnload
  101. } from '@dcloudio/uni-app'
  102. import memberLevel from "./components/memberLevel.vue"
  103. import treeAlbumPopup from "./components/treeAlbumPopup.vue"
  104. import blessingsPopup from "./components/blessingsPopup.vue"
  105. import danmakuManager from "@/components/danmakuManager/danmakuManager.vue"
  106. import TREE from '@/api/tree.js'
  107. import USER from '@/api/user.js'
  108. import {
  109. ref
  110. } from 'vue';
  111. const name = ref('荔枝')
  112. const showPicker = ref(false)
  113. const columns = ref([]);
  114. const speciesId = ref('')
  115. const handleShow = () => {
  116. showPicker.value = true
  117. }
  118. const handleCancel = () => {
  119. showPicker.value = false
  120. }
  121. const handleConfirm = (e) => {
  122. name.value = e.value[0].name
  123. speciesId.value = e.value[0].speciesId
  124. handleCancel()
  125. }
  126. const toolLeftList = [{
  127. name: "相册",
  128. clickName: 'album'
  129. },
  130. {
  131. name: "日记",
  132. path: 'diary'
  133. },
  134. {
  135. name: "海报",
  136. className: 'blue',
  137. clickName: 'poster'
  138. },
  139. {
  140. name: "礼物",
  141. className: 'gift',
  142. path: 'gift'
  143. }
  144. ]
  145. const toolRightList = [{
  146. name: "好友",
  147. className: 'friend',
  148. path: 'rank'
  149. },
  150. {
  151. name: "认养",
  152. },
  153. {
  154. name: "果园",
  155. },
  156. {
  157. name: "动态",
  158. className: 'dynamic',
  159. path: 'dynamic',
  160. params: 'farmBuyId'
  161. }
  162. ]
  163. const showGuardSuccess = ref(false)
  164. const editNameRef = ref(null)
  165. const formatDate = (dateStr) => {
  166. return dateStr.split(" ")[0].replace(/-/g, ".");
  167. };
  168. const handleEditName = () => {
  169. editNameRef.value.showPopup({
  170. id: farmBuyId.value,
  171. treeName: treeName.value,
  172. nickname: treeData.value.buyList[0].nickname,
  173. showName: treeData.value.buyList[0].showName,
  174. createDate: formatDate(treeData.value.buyList[0].createDate),
  175. })
  176. }
  177. const userInfo = ref({})
  178. onLoad(() => {
  179. featchIsLookedGuide()
  180. featchCategoryList()
  181. })
  182. onShow(()=>{
  183. userInfo.value = uni.getStorageSync('userInfo')
  184. const isUpdateName = uni.getStorageSync('isUpdateName')
  185. if(isUpdateName === 'true'){
  186. featchLightTree()
  187. uni.setStorageSync('isUpdateName','false')
  188. }
  189. featchSessionStore()
  190. // 页面显示时启动弹幕
  191. startDanmaku()
  192. })
  193. onHide(() => {
  194. // 页面隐藏时停止弹幕
  195. stopDanmaku()
  196. })
  197. onUnload(() => {
  198. // 页面卸载时停止弹幕
  199. stopDanmaku()
  200. })
  201. //品类查询所有
  202. const featchCategoryList = () =>{
  203. TREE.categoryList().then(({
  204. data
  205. }) => {
  206. columns.value[0] = data || []
  207. speciesId.value = data[0].speciesId
  208. featchLightTree()
  209. })
  210. }
  211. const showMask = ref(false)
  212. const featchIsLookedGuide = () => {
  213. USER.isLookedGuide({
  214. type: 1
  215. }).then(({
  216. data
  217. }) => {
  218. if (data == false) {
  219. showMask.value = true
  220. }
  221. })
  222. }
  223. const handleClose = async () =>{
  224. const {code} = await USER.lookedGuide({type:1})
  225. if(code === 0){
  226. showMask.value = false
  227. }
  228. }
  229. const featchSessionStore = () => {
  230. USER.getSessionStore({
  231. key: 'successTree',
  232. miniUserId: userInfo.value.id
  233. }).then((({data}) => {
  234. if(data?.text === 'orderSuccess'){
  235. clockinType.value = 4
  236. showSuccess.value = !showSuccess.value
  237. treeSetSessionStore()
  238. }else{
  239. if (data?.val == 0) {
  240. showGuardSuccess.value = !showGuardSuccess.value
  241. treeSetSessionStore()
  242. }
  243. }
  244. }))
  245. }
  246. const treeSetSessionStore = () =>{
  247. USER.setSessionStore({
  248. key: 'successTree',
  249. miniUserId: userInfo.value.id,
  250. val:1,
  251. text:'1'
  252. })
  253. }
  254. const closedCheckPopup = () =>{
  255. showPoster.value = !showPoster.value
  256. }
  257. const sampleId = ref('')
  258. //通过品类查询当前树
  259. const featchLightTree = () =>{
  260. TREE.getLightTreeList().then((res =>{
  261. sampleId.value = res.data[0].sampleId
  262. getBySampleId()
  263. }))
  264. }
  265. const treeData = ref({})
  266. const farmBuyId = ref('')
  267. const treeName = ref('')
  268. const getBySampleId = () => {
  269. TREE.getBySampleId({
  270. sampleId: sampleId.value
  271. }).then(({
  272. data
  273. }) => {
  274. treeData.value = data || {}
  275. if (userInfo.value.tel) {
  276. treeName.value = data.buyList[0].treeName || (data.buyList[0].nickname.length ? data.buyList[0]
  277. .nickname.slice(0, 3) + "荔" : data.buyList[0].owner.slice(0, 3) + "荔")
  278. } else {
  279. treeName.value = '飞鸟守护'
  280. }
  281. farmBuyId.value = data.buyList[0].id
  282. featchSessionStore()
  283. })
  284. }
  285. const handlePage = () =>{
  286. uni.navigateTo({
  287. url: `/pages/login/index`
  288. });
  289. }
  290. const showPoster = ref(false)
  291. const showAlbum = ref(false)
  292. const handleToolItem = ({
  293. path,
  294. clickName,
  295. params
  296. }) => {
  297. if (clickName === 'album') {
  298. showAlbum.value = !showAlbum.value
  299. } else if (clickName === 'poster') {
  300. showPoster.value = !showPoster.value
  301. } else {
  302. uni.navigateTo({
  303. url: `/pages/tabBar/tree/subPages/${path}?farmBuyId=${farmBuyId.value}&sampleId=${sampleId.value}`
  304. });
  305. }
  306. }
  307. const footerList = ["每日阳光", "送ta祝福", "分享转发", "水果订购"]
  308. const showBlessingsPopup = ref(false)
  309. const showSuccess = ref(false)
  310. const clockinType = ref('1')
  311. // 弹幕相关数据
  312. const danmakuList = ref([
  313. {
  314. text: "晨曦微露,阳光洒满大地",
  315. avatar: `${userInfo.value.icon}`
  316. },
  317. {
  318. text: "守护果树,收获美好",
  319. avatar: `${userInfo.value.icon}`
  320. },
  321. {
  322. text: "今天也要给果树浇水哦",
  323. avatar: `${userInfo.value.icon}`
  324. },
  325. {
  326. text: "果树长得好快啊",
  327. avatar: `${config.BASIC_IMG}img/treePage/drone-icon.png`
  328. },
  329. {
  330. text: "期待果实成熟的那一天",
  331. avatar: `${config.BASIC_IMG}img/treePage/drone-icon.png`
  332. },
  333. {
  334. text: "和好友一起守护果树",
  335. avatar: `${config.BASIC_IMG}img/treePage/drone-icon.png`
  336. },
  337. {
  338. text: "每日签到,果树茁壮成长",
  339. avatar: `${config.BASIC_IMG}img/treePage/drone-icon.png`
  340. },
  341. {
  342. text: "分享给更多朋友",
  343. avatar: `${config.BASIC_IMG}img/treePage/drone-icon.png`
  344. }
  345. ])
  346. // 弹幕组件引用
  347. const danmakuRef = ref(null)
  348. // 弹幕完成回调
  349. const onDanmakuComplete = (id) => {
  350. // console.log('弹幕播放完成:', id)
  351. }
  352. // 启动弹幕
  353. const startDanmaku = () => {
  354. if (danmakuRef.value) {
  355. danmakuRef.value.startDanmakuAnimation()
  356. }
  357. }
  358. // 停止弹幕
  359. const stopDanmaku = () => {
  360. if (danmakuRef.value) {
  361. danmakuRef.value.stopDanmakuAnimation()
  362. }
  363. }
  364. const handleItem = (index) => {
  365. if (index === 0) {
  366. clockinType.value = 1
  367. if (treeData.value.buyList[0].level.clockinMap['1']) {
  368. uni.showToast({
  369. title: '今日已守护',
  370. icon: 'none',
  371. duration: 2000
  372. });
  373. } else {
  374. showSuccess.value = !showSuccess.value
  375. }
  376. } else if (index === 1) {
  377. clockinType.value = 3
  378. if (treeData.value.buyList[0].level.clockinMap['3']) {
  379. uni.showToast({
  380. title: '今日已送过祝福',
  381. icon: 'none',
  382. duration: 2000
  383. });
  384. } else {
  385. showBlessingsPopup.value = !showBlessingsPopup.value
  386. }
  387. } else if (index === 2) {
  388. clockinType.value = 2
  389. if (!treeData.value.buyList[0].level.clockinMap['2']) {
  390. showSuccess.value = !showSuccess.value
  391. }
  392. } else {
  393. uni.navigateTo({
  394. url: `/pages/tabBar/home/subPages/gardenItem`
  395. });
  396. }
  397. }
  398. function requestSubscribe() {
  399. // #ifdef MP-WEIXIN
  400. //订阅模板
  401. TREE.getSubscribeTemplate({
  402. id: 1
  403. }).then(({
  404. data
  405. }) => {
  406. uni.requestSubscribeMessage({
  407. tmplIds: [data.templateId], // 模板ID
  408. success(res) {
  409. if (res[data.templateId] === 'accept') {
  410. TREE.addSubscribe({
  411. templateId: 1
  412. })
  413. } else if (res[data.templateId] === 'reject') {
  414. console.log('用户拒绝订阅模板');
  415. }
  416. },
  417. fail(err) {
  418. uni.openSetting({
  419. withSubscriptions: true, // 显示订阅消息开关
  420. });
  421. },
  422. });
  423. })
  424. // #endif
  425. }
  426. onShareAppMessage((res) => {
  427. return {
  428. title: '我分享了我的果树,快来查看吧~',
  429. path: `/pages/tabBar/tree/subPages/friendTree?sampleId=${sampleId.value}`, // 分享的小程序页面路径
  430. imageUrl: `http://birdseye-api.feiniaotech.sysuimars.cn/mini/z_farm_buy/genImage/${farmBuyId.value}?key=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9&x1=25&y1=220&fontSize1=40&x2=55&y2=250&fontSize2=16&timestamp=${Date.now()}`,
  431. }
  432. })
  433. </script>
  434. <style lang="scss" scoped>
  435. @import "@/static/style/mixin.scss";
  436. .guide-bg{
  437. position: fixed;
  438. top: 0;
  439. width: 100%;
  440. height: 107vh;
  441. @include ossBg("treePage/guide-bg.png");
  442. z-index: 999;
  443. display: flex;
  444. align-items: center;
  445. justify-content: center;
  446. .guide-icon{
  447. width: 360rpx;
  448. height: 236rpx
  449. }
  450. }
  451. /* #ifdef H5 */
  452. .guide-bg{
  453. height: 102vh;
  454. }
  455. /* #endif */
  456. .base-container {
  457. @include ossBg("tree-bg.png");
  458. // background-position: top left;
  459. padding: 22rpx 0;
  460. position: relative;
  461. .danmaku-wrapper {
  462. position: absolute;
  463. top: 21%;
  464. left: 0;
  465. right: 0;
  466. z-index: 100;
  467. pointer-events: none;
  468. }
  469. .toogle {
  470. position: absolute;
  471. right: 0;
  472. top: calc(50% - 32rpx);
  473. font-size: 24rpx;
  474. color: #fff;
  475. border-radius: 50rpx 0 0 50rpx;
  476. background: rgba(0, 0, 0, 0.2);
  477. padding: 12rpx 20rpx;
  478. display: flex;
  479. .icon {
  480. margin-left: 10rpx;
  481. }
  482. }
  483. .tree-cont {
  484. width: 100%;
  485. margin-top: 10rpx;
  486. .dialogue-tips{
  487. position: absolute;
  488. top: 31.5%;
  489. right: 80rpx;
  490. font-size: 24rpx;
  491. @include ossBg("treePage/tips-bg.png");
  492. padding: 10rpx 10rpx 30rpx 20rpx;
  493. .tips-name{
  494. font-size: 28rpx;
  495. font-weight: 500;
  496. margin-bottom: 6rpx;
  497. display: flex;
  498. align-items: center;
  499. .tip-img{
  500. width: 40rpx;
  501. height: 40rpx;
  502. margin-right: 4rpx;
  503. }
  504. }
  505. }
  506. .tree-name {
  507. position: absolute;
  508. top: 60.45%;
  509. left: calc(50% - 32rpx);
  510. z-index: 2;
  511. font-size: 22rpx;
  512. font-family: 'SweiSpringCJKtc';
  513. text-align: center;
  514. width: 88rpx;
  515. .edit-icon {
  516. width: 44rpx;
  517. height: 44rpx;
  518. margin-top: 14rpx;
  519. }
  520. }
  521. .drone-icon {
  522. width: 376rpx;
  523. height: 384rpx;
  524. margin-left: 26rpx;
  525. }
  526. .tool-wrap {
  527. width: 100%;
  528. padding: 14rpx;
  529. box-sizing: border-box;
  530. position: absolute;
  531. bottom: calc(50% - 350rpx);
  532. display: flex;
  533. justify-content: space-between;
  534. .tool-left,
  535. .tool-right {
  536. .tool-item {
  537. color: #fff;
  538. font-size: 24rpx;
  539. font-weight: 500;
  540. text-align: center;
  541. width: 100rpx;
  542. margin-bottom: 16rpx;
  543. text-shadow:
  544. 0 0 3rpx #D7660A,
  545. 0 0 3rpx #D7660A,
  546. 0 0 3rpx #D7660A,
  547. 0 0 3rpx #D7660A;
  548. &.blue {
  549. text-shadow:
  550. 0 0 3rpx #2199F8,
  551. 0 0 3rpx #2199F8,
  552. 0 0 3rpx #2199F8,
  553. 0 0 3rpx #2199F8;
  554. }
  555. .icon {
  556. width: 100%;
  557. height: 82rpx;
  558. position: relative;
  559. }
  560. .name {
  561. margin-top: -24rpx;
  562. position: relative;
  563. z-index: 2;
  564. }
  565. &.gift {
  566. .icon {
  567. height: 114rpx;
  568. margin-top: -5rpx;
  569. }
  570. .name {
  571. margin-top: -44rpx;
  572. }
  573. }
  574. &.friend {
  575. .icon {
  576. height: 90rpx;
  577. }
  578. .name {
  579. margin-top: -35rpx;
  580. }
  581. }
  582. &.dynamic {
  583. .icon {
  584. height: 96rpx;
  585. }
  586. .name {
  587. margin-top: -32rpx;
  588. }
  589. }
  590. }
  591. }
  592. }
  593. }
  594. .tree-footer {
  595. position: absolute;
  596. left: 0;
  597. bottom: 76rpx;
  598. width: 100%;
  599. display: flex;
  600. justify-content: center;
  601. .button {
  602. padding: 26rpx 80rpx;
  603. border-radius: 50rpx;
  604. border: 2rpx solid #fff;
  605. background-image: linear-gradient(120deg, #FFD887, #ED9E1E);
  606. margin-top: 20rpx;
  607. color: #fff;
  608. }
  609. .footer-item {
  610. width: 18%;
  611. text-align: center;
  612. .icon {
  613. width: 96rpx;
  614. height: 96rpx;
  615. }
  616. .share-btn {
  617. background: transparent;
  618. display: inline-flex;
  619. .icon {
  620. width: 90rpx;
  621. height: 90rpx;
  622. margin-top: 6rpx;
  623. }
  624. &::after {
  625. border: none;
  626. }
  627. }
  628. .small{
  629. width: 90rpx;
  630. height: 90rpx;
  631. margin-top: 6rpx;
  632. }
  633. .name {
  634. font-size: 24rpx;
  635. font-weight: 500;
  636. padding: 2rpx 16rpx;
  637. background-image: linear-gradient(0deg, #FFFFFF, #FFE079);
  638. border-radius: 50rpx;
  639. border: 2rpx solid #fff;
  640. }
  641. }
  642. .footer-item+.footer-item {
  643. margin-left: 30rpx;
  644. }
  645. }
  646. }
  647. </style>