tree.vue 16 KB

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