tree.vue 16 KB

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