tree.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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"></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. userInfo.value = uni.getStorageSync('userInfo')
  180. featchIsLookedGuide()
  181. featchCategoryList()
  182. })
  183. onShow(()=>{
  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. if (res.from === 'button') {
  428. const params = {
  429. sampleId: treeData.value.buyList[0].sampleId,
  430. farmId: treeData.value.buyList[0].farmId,
  431. }
  432. return {
  433. title: '我分享了我的果树,快来查看吧~',
  434. path: `/pages/tabBar/tree/subPages/friendTree?params=${JSON.stringify(params)}`, // 分享的小程序页面路径
  435. 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()}`,
  436. }
  437. }
  438. })
  439. </script>
  440. <style lang="scss" scoped>
  441. @import "@/static/style/mixin.scss";
  442. .guide-bg{
  443. position: fixed;
  444. top: 0;
  445. width: 100%;
  446. height: 107vh;
  447. @include ossBg("treePage/guide-bg.png");
  448. z-index: 999;
  449. display: flex;
  450. align-items: center;
  451. justify-content: center;
  452. .guide-icon{
  453. width: 360rpx;
  454. height: 236rpx
  455. }
  456. }
  457. /* #ifdef H5 */
  458. .guide-bg{
  459. height: 102vh;
  460. }
  461. /* #endif */
  462. .base-container {
  463. @include ossBg("tree-bg.png");
  464. // background-position: top left;
  465. padding: 22rpx 0;
  466. position: relative;
  467. .danmaku-wrapper {
  468. position: absolute;
  469. top: 21%;
  470. left: 0;
  471. right: 0;
  472. z-index: 100;
  473. pointer-events: none;
  474. }
  475. .toogle {
  476. position: absolute;
  477. right: 0;
  478. top: calc(50% - 32rpx);
  479. font-size: 24rpx;
  480. color: #fff;
  481. border-radius: 50rpx 0 0 50rpx;
  482. background: rgba(0, 0, 0, 0.2);
  483. padding: 12rpx 20rpx;
  484. display: flex;
  485. .icon {
  486. margin-left: 10rpx;
  487. }
  488. }
  489. .tree-cont {
  490. width: 100%;
  491. margin-top: 10rpx;
  492. .dialogue-tips{
  493. position: absolute;
  494. top: 31.5%;
  495. right: 80rpx;
  496. font-size: 24rpx;
  497. @include ossBg("treePage/tips-bg.png");
  498. padding: 10rpx 10rpx 30rpx 20rpx;
  499. .tips-name{
  500. font-size: 28rpx;
  501. font-weight: 500;
  502. margin-bottom: 6rpx;
  503. display: flex;
  504. align-items: center;
  505. .tip-img{
  506. width: 40rpx;
  507. height: 40rpx;
  508. margin-right: 4rpx;
  509. }
  510. }
  511. }
  512. .tree-name {
  513. position: absolute;
  514. top: 60.45%;
  515. left: calc(50% - 32rpx);
  516. z-index: 2;
  517. font-size: 22rpx;
  518. font-family: 'SweiSpringCJKtc';
  519. text-align: center;
  520. width: 88rpx;
  521. .edit-icon {
  522. width: 44rpx;
  523. height: 44rpx;
  524. margin-top: 14rpx;
  525. }
  526. }
  527. .drone-icon {
  528. width: 376rpx;
  529. height: 384rpx;
  530. margin-left: 26rpx;
  531. }
  532. .tool-wrap {
  533. width: 100%;
  534. padding: 14rpx;
  535. box-sizing: border-box;
  536. position: absolute;
  537. bottom: calc(50% - 350rpx);
  538. display: flex;
  539. justify-content: space-between;
  540. .tool-left,
  541. .tool-right {
  542. .tool-item {
  543. color: #fff;
  544. font-size: 24rpx;
  545. font-weight: 500;
  546. text-align: center;
  547. width: 100rpx;
  548. margin-bottom: 16rpx;
  549. text-shadow:
  550. 0 0 3rpx #D7660A,
  551. 0 0 3rpx #D7660A,
  552. 0 0 3rpx #D7660A,
  553. 0 0 3rpx #D7660A;
  554. &.blue {
  555. text-shadow:
  556. 0 0 3rpx #2199F8,
  557. 0 0 3rpx #2199F8,
  558. 0 0 3rpx #2199F8,
  559. 0 0 3rpx #2199F8;
  560. }
  561. .icon {
  562. width: 100%;
  563. height: 82rpx;
  564. position: relative;
  565. }
  566. .name {
  567. margin-top: -24rpx;
  568. position: relative;
  569. z-index: 2;
  570. }
  571. &.gift {
  572. .icon {
  573. height: 114rpx;
  574. margin-top: -5rpx;
  575. }
  576. .name {
  577. margin-top: -44rpx;
  578. }
  579. }
  580. &.friend {
  581. .icon {
  582. height: 90rpx;
  583. }
  584. .name {
  585. margin-top: -35rpx;
  586. }
  587. }
  588. &.dynamic {
  589. .icon {
  590. height: 96rpx;
  591. }
  592. .name {
  593. margin-top: -32rpx;
  594. }
  595. }
  596. }
  597. }
  598. }
  599. }
  600. .tree-footer {
  601. position: absolute;
  602. left: 0;
  603. bottom: 76rpx;
  604. width: 100%;
  605. display: flex;
  606. justify-content: center;
  607. .button {
  608. padding: 26rpx 80rpx;
  609. border-radius: 50rpx;
  610. border: 2rpx solid #fff;
  611. background-image: linear-gradient(120deg, #FFD887, #ED9E1E);
  612. margin-top: 20rpx;
  613. color: #fff;
  614. }
  615. .footer-item {
  616. width: 18%;
  617. text-align: center;
  618. .icon {
  619. width: 96rpx;
  620. height: 96rpx;
  621. }
  622. .share-btn {
  623. background: transparent;
  624. display: inline-flex;
  625. .icon {
  626. width: 90rpx;
  627. height: 90rpx;
  628. margin-top: 6rpx;
  629. }
  630. &::after {
  631. border: none;
  632. }
  633. }
  634. .small{
  635. width: 90rpx;
  636. height: 90rpx;
  637. margin-top: 6rpx;
  638. }
  639. .name {
  640. font-size: 24rpx;
  641. font-weight: 500;
  642. padding: 2rpx 16rpx;
  643. background-image: linear-gradient(0deg, #FFFFFF, #FFE079);
  644. border-radius: 50rpx;
  645. border: 2rpx solid #fff;
  646. }
  647. }
  648. .footer-item+.footer-item {
  649. margin-left: 30rpx;
  650. }
  651. }
  652. }
  653. </style>