tree.vue 16 KB

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