bottom-func.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <view>
  3. <view class="cu-modal bottom-modal" :class="show ? 'show' : ''" @click="close">
  4. <view class="cu-dialog" @click.stop="() => {}">
  5. <view class="cu-bar bg-white justify-end">
  6. <view class="content">我的</view>
  7. <view class="action" @click="close">
  8. <text class="cuIcon-close"></text>
  9. </view>
  10. </view>
  11. <view class="padding-sm content">
  12. <view class="padding-lr-xs">
  13. <view class="flex align-start">
  14. <view class="cu-avatar lg">VIP</view>
  15. <view class="flex flex-direction align-start margin-xs margin-left">
  16. <view>普通用户</view>
  17. <view @click="usernameSimple && $squni.copy(usernameSimple)">ID:
  18. <text class="text-bold">{{ usernameSimple || '尚未登录' }}</text>
  19. <text class="cuIcon-copy text-cyan margin-left-xs"></text>
  20. </view>
  21. </view>
  22. </view>
  23. <view class="flex align-start margin-top">
  24. <!-- <view class="cu-capsule">-->
  25. <!-- <view class='cu-tag radius bg-cyan'>拥有额度</view>-->
  26. <!-- <view class="cu-tag line-cyan">{{ chatAsset.n || 0 }}次</view>-->
  27. <!-- </view>-->
  28. <view class="cu-capsule">
  29. <view class='cu-tag radius bg-cyan'>每日免费剩余额度</view>
  30. <view class="cu-tag line-cyan">{{ chatAsset.dfn || 0 }}次</view>
  31. </view>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. </view>
  38. </template>
  39. <script>
  40. import BottomDrawer from '@/components/bottom-drawer/bottom-drawer.vue'
  41. import { mapGetters } from 'vuex'
  42. import {
  43. rewardedVideoAdAssetApi
  44. } from '@/api/chat.js'
  45. let rewardedVideoAd = null
  46. export default {
  47. components: { BottomDrawer },
  48. props: {
  49. chatAsset: {
  50. type: Object,
  51. default: () => {}
  52. }
  53. },
  54. data() {
  55. return {
  56. show: true,
  57. showVip: false,
  58. showNum: false,
  59. showCustomer: false,
  60. cuIconList: [{
  61. cuIcon: 'vip',
  62. color: 'orange',
  63. name: '开通会员',
  64. callback: () => {
  65. this.showVip = true
  66. }
  67. }, {
  68. cuIcon: 'baby',
  69. color: 'blue',
  70. name: '次数包',
  71. callback: () => {
  72. this.showNum = true
  73. }
  74. }, {
  75. cuIcon: 'service',
  76. color: 'cyan',
  77. name: '客服领次数',
  78. type: 'button',
  79. callback: () => {
  80. // #ifndef MP-WEIXIN
  81. this.showCustomer = true
  82. // #endif
  83. }
  84. }, {
  85. cuIcon: 'flashlightclose',
  86. color: 'red',
  87. name: '清除记忆',
  88. callback: () => {
  89. this.$squni.setStorageSync('chatHistory', [])
  90. this.$squni.toast('清除记忆成功', 'success')
  91. }
  92. }],
  93. rewardedCount: 0
  94. };
  95. },
  96. computed: {
  97. ...mapGetters([
  98. 'usernameSimple'
  99. ]),
  100. showFuncList () {
  101. return this.showVip || this.showNum || this.showCustomer
  102. }
  103. },
  104. watch: {
  105. showFuncList (n, o) {
  106. if (n !== o) {
  107. this.show = !n
  108. }
  109. }
  110. },
  111. created() {
  112. // #ifdef MP-WEIXIN
  113. if (wx.createRewardedVideoAd) {
  114. rewardedVideoAd = wx.createRewardedVideoAd({
  115. adUnitId: this.$config.wxRewardedVideoAd
  116. })
  117. rewardedVideoAd.onLoad(() => {
  118. // 激励视频广告加载成功。用户观看完会重新加载新的广告并重新进入此方法
  119. console.log('onLoad event emit')
  120. })
  121. rewardedVideoAd.onClose(res => {
  122. // 用户点击了【关闭广告】按钮
  123. if (res && res.isEnded) {
  124. // 正常播放结束,可以下发游戏奖励
  125. rewardedVideoAdAssetApi().then(res => {
  126. this.rewardedCount = res.data.rewardedCount
  127. if(res.status === 'success') {
  128. this.$squni.toast(`已增加次数${this.rewardedCount >= 5 ? '(今日次数已用完)' : ''}`, 'success')
  129. this.$emit('rewarded-video-ad')
  130. }
  131. })
  132. } else {
  133. // 播放中途退出,不下发游戏奖励;退出前ad组件会自动进行confirm
  134. }
  135. })
  136. rewardedVideoAd.onError((err) => {
  137. console.log('onError event emit', err)
  138. })
  139. }
  140. // #endif
  141. },
  142. methods: {
  143. open() {
  144. this.show = true;
  145. },
  146. close() {
  147. this.show = false;
  148. },
  149. navigateTo(item) {
  150. if (item.callback) {
  151. item.callback(item)
  152. } else {
  153. uni.navigateTo({
  154. url: item.page
  155. })
  156. }
  157. },
  158. oepnRewardedVideoAd () {
  159. // #ifdef MP-WEIXIN
  160. if (rewardedVideoAd) {
  161. if(this.rewardedCount >= 5) {
  162. this.$squni.toast('今日次数已用完,明天再来吧~')
  163. return
  164. }
  165. rewardedVideoAd.show().catch(() => {
  166. // 失败重试
  167. rewardedVideoAd.load()
  168. .then(() => rewardedVideoAd.show())
  169. .catch(err => {
  170. // https://developers.weixin.qq.com/miniprogram/dev/api/ad/RewardedVideoAd.onError.html
  171. console.log('激励视频广告显示失败', err)
  172. this.$squni.toast('广告加载失败了,请稍后再试~')
  173. })
  174. })
  175. }
  176. // #endif
  177. }
  178. }
  179. };
  180. </script>
  181. <style lang="scss">
  182. .cu-dialog {
  183. border-radius: 20upx 20upx 0 0;
  184. }
  185. .content {
  186. background-color: #fff;
  187. padding-top: 16upx;
  188. }
  189. .cu-bar .content {
  190. color: #333333;
  191. font-weight: 700;
  192. }
  193. .cu-list {
  194. margin-bottom: 20upx;
  195. }
  196. .cu-list .func-list {
  197. margin: 0upx 20upx -20upx 0;
  198. }
  199. .cu-list .func-list .func-icon {
  200. border: 1px solid #eee;
  201. border-radius: 8upx;
  202. padding: 30upx;
  203. font-size: 80upx;
  204. }
  205. .cu-list.grid>.cu-item.item-button {
  206. padding: 0;
  207. .cu-btn {
  208. display: inline-block;
  209. background: transparent;
  210. height: 164upx;
  211. margin-top: 0;
  212. padding-right: 20upx;
  213. border-radius: 0;
  214. .button-icon {
  215. border: 1px solid #eee;
  216. padding: 30upx 0upx 36upx 0;
  217. margin-top: 28upx;
  218. }
  219. .cuIcon-service:before {
  220. /* #ifdef H5 */
  221. font-size: 84upx;
  222. /* #endif */
  223. }
  224. }
  225. }
  226. </style>