home.uvue 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <script lang="ts" setup>
  2. import { computed, onMounted, ref } from 'vue'
  3. import { dict } from '@/.cool/store'
  4. import { router } from '@/.cool'
  5. import { user } from '@/.cool'
  6. import Physics from './components/physics.uvue'
  7. import Chinese from './components/chinese.uvue'
  8. import English from './components/english.uvue'
  9. import Mix from './components/mix.uvue'
  10. import Game from './components/game.uvue'
  11. import Exchange from './components/exchange.uvue'
  12. import MathModal from './components/math.uvue'
  13. import { bindWechatOpenId } from "@/services/user";
  14. import { useUi } from "@/uni_modules/cool-ui";
  15. import { exchangeCode } from '@/services/user'
  16. const ui = useUi();
  17. const menuList = computed(() => {
  18. return [
  19. ...dict.getChildrenList('index_subject_id'),
  20. {
  21. label: '少儿编程',
  22. code: 'coding'
  23. },
  24. {
  25. label: '兑换',
  26. code: 'exchange'
  27. },
  28. {
  29. label: '个人中心',
  30. code: 'user'
  31. },
  32. ]
  33. })
  34. const icons = {
  35. physics: "https://oss.xiaoxiongcode.com/static/home/wl.png",
  36. chinese: "https://oss.xiaoxiongcode.com/static/home/语文.png",
  37. english: "https://oss.xiaoxiongcode.com/static/home/英语.png",
  38. mix: "https://oss.xiaoxiongcode.com/static/home/百度百科.png",
  39. game: "https://oss.xiaoxiongcode.com/static/home/娱乐.png",
  40. exchange: "https://oss.xiaoxiongcode.com/static/home/图层 5.png",
  41. user: "https://oss.xiaoxiongcode.com/static/home/个人中心.png",
  42. math: "https://oss.xiaoxiongcode.com/static/home/math.png",
  43. coding: "https://oss.xiaoxiongcode.com/static/home/coding.png",
  44. }
  45. const selected = ref<string>('physics')
  46. function handlePage(val: any) {
  47. if (val.code === 'user') {
  48. router.push({ path: '/pages/user/info' })
  49. return
  50. }
  51. if (val.code === 'coding') {
  52. visible2.value = true
  53. return
  54. }
  55. selected.value = val.code
  56. }
  57. const userInfo = computed(() => user.info.value?.userInfo)
  58. const visible = ref(false)
  59. const visible2 = ref(false)
  60. const visible3 = ref(false)
  61. const visible4 = ref(false)
  62. onMounted(async () => {
  63. if (!userInfo.value.wxOpenId) {
  64. visible4.value = true
  65. return
  66. } else if (userInfo.value.memberLevel === 'default') {
  67. visible3.value = true
  68. return
  69. }
  70. })
  71. async function handleClosePopup1() {
  72. await handleBind()
  73. visible4.value = false
  74. if (userInfo.value.memberLevel === 'default') {
  75. visible3.value = true
  76. }
  77. }
  78. function handleClosePopup2() {
  79. visible4.value = false
  80. userInfo.value.wxOpenId = true
  81. if (userInfo.value.memberLevel === 'default') {
  82. visible3.value = true
  83. }
  84. }
  85. function copyUrl() {
  86. uni.setClipboardData({
  87. data: 'www.xiaoxiongcode.com',
  88. success: (res) => {
  89. uni.showToast({
  90. title: '复制成功',
  91. icon: 'success'
  92. });
  93. }
  94. });
  95. }
  96. const handleBind = async () => {
  97. uni.login({
  98. provider: 'weixin',
  99. success: async (res) => {
  100. await bindWechatOpenId({ code: res.code })
  101. uni.showToast({
  102. title: '授权成功,请重新登录'
  103. })
  104. await user.get()
  105. }
  106. })
  107. }
  108. const code = ref<string>('')
  109. async function handleExchange() {
  110. if (!code.value) {
  111. uni.showToast({
  112. title: '请输入兑换码',
  113. icon: 'none'
  114. })
  115. return
  116. }
  117. try {
  118. await exchangeCode({
  119. exchangeCode: code.value,
  120. subjectId: dict.getValueByLabelMapByType('index_subject_id')['物理'],
  121. })
  122. await user.get()
  123. ui.showConfirm({
  124. title: "提示",
  125. message: "兑换成功",
  126. showCancel: false,
  127. callback(action) {
  128. visible3.value = false
  129. },
  130. });
  131. } catch (err: any) {
  132. uni.showToast({
  133. title: err.message,
  134. icon: 'error'
  135. })
  136. }
  137. }
  138. </script>
  139. <template>
  140. <cl-page :backTop="false">
  141. <image src="https://oss.xiaoxiongcode.com/static/home/111.png" mode="aspectFill" lazy-load alt=""
  142. class="w-full h-full object-cover absolute top-0 left-0" />
  143. <view class="menus w-[90vw]">
  144. <image lazy-load src="https://oss.xiaoxiongcode.com/static/home/643.png"
  145. class="w-[90vw] h-[24vh] absolute top-0 left-0 z-[1]"></image>
  146. <view class="w-[87vw] relative z-[2] p-1 px-3 flex flex-row items-center justify-between gap-1 mx-auto ">
  147. <view v-for="item in menuList" :key="item.code"
  148. class="flex flex-col items-center p-1 px-4 justify-center gap-1 transition-all duration-300"
  149. @tap="handlePage(item)" :class="{ 'selected': item.code === selected }">
  150. <image lazy-load :src="icons[item.code]" mode="aspectFill" class="w-[4vw] h-[4vw]"></image>
  151. <text class="text-[1.5vw] text-[#1E1E1E]">{{ item.label }}</text>
  152. </view>
  153. </view>
  154. </view>
  155. <cl-float-view :left="20" :bottom="100" v-if="!userInfo.roleCodes?.includes('show_time')">
  156. <view
  157. class="flex flex-col items-center p-1 px-4 justify-center gap-1 w-[40px] h-[40px] transition-all duration-300"
  158. @tap="visible = true">
  159. <view class="bg-[#09ba07] p-[1vw] rounded-full w-[40px] h-[40px] flex items-center justify-center"
  160. @tap="visible = true">
  161. <cl-icon name="customer-service-line" :size="20" color="#FFF"></cl-icon>
  162. </view>
  163. </view>
  164. </cl-float-view>
  165. <!-- <view class="flex flex-col items-center justify-center fixed bottom-[3vh] right-[3vh] ">
  166. <view class="bg-[#09ba07] p-2 rounded-full border-[2px] border-[#FFF] border-solid " @tap="visible = true">
  167. <image src="https://oss.xiaoxiongcode.com/static/个人中心/微信.png" class="w-5 h-5"></image>
  168. </view>
  169. <text class="text-[14px] text-white font-bold text-stroke">添加老师</text>
  170. </view> -->
  171. <cl-popup v-model="visible" :size="400" :show-header="false" direction="center">
  172. <view class="flex flex-col items-center justify-center gap-4 py-7 bg-slate-50">
  173. <cl-text class="text-center " color="#09ba07" :size="30"> ——专属服务内容—— </cl-text>
  174. <image src="https://oss.xiaoxiongcode.com/static/home/qr.png" show-menu-by-longpress
  175. class="w-32 h-32" />
  176. <view class="text-center "> <cl-text class="text-center" color="#999" :size="14"> 长按识别二维码 </cl-text>
  177. <cl-text class="text-center" color="#999" :size="14"> 添加微信,享专业老师服务 </cl-text>
  178. </view>
  179. </view>
  180. </cl-popup>
  181. <cl-popup v-model="visible2" :size="400" :show-header="false" direction="center">
  182. <view class="flex flex-col items-center justify-center gap-4 py-7 bg-slate-50">
  183. <cl-text class="text-center " color="#09ba07" :size="30"> ——会员福利—— </cl-text>
  184. <image src="https://oss.xiaoxiongcode.com/static/home/coding.png" class="w-32 h-32" />
  185. <view class="text-center " v-if="userInfo?.memberLevel !== 'default'">
  186. <cl-text class="text-center" color="#999" :size="14">账号:小程序登录手机账号 </cl-text>
  187. <cl-text class="text-center" color="#999" :size="14"> 密码:初始密码为123456 </cl-text>
  188. <cl-text class="text-center" v-if="!userInfo.roleCodes?.includes('show_time')" color="#999"
  189. :size="14">少儿编程网址: www.xiaoxiongcode.com </cl-text>
  190. <cl-text class="text-center" v-else color="#999" :size="14">少儿编程网址: ************* </cl-text>
  191. <cl-button type="primary" size="small" @tap="copyUrl"> 复制网址 </cl-button>
  192. </view>
  193. <view class="text-center " v-else>
  194. <cl-text class="text-center" color="#999" :size="14"> 您不是会员,无法使用会员福利 </cl-text>
  195. </view>
  196. </view>
  197. </cl-popup>
  198. <cl-popup v-model="visible3" showClose :size="400" :show-header="false" direction="center">
  199. <view class="flex flex-col items-center justify-center gap-4 py-7 bg-slate-50">
  200. <cl-text class="text-center " color="#333" :size="25"> ——激活会员—— </cl-text>
  201. <input
  202. class="w-[200px] h-[40px] bg-[#F5F5F5] border-[1px] border-[#333] border-solid rounded-[20px] px-[10px]"
  203. v-model="code" placeholder="请输入兑换码"></input>
  204. <cl-button class="mt-4" size="large" type="primary" block @tap="handleExchange"> 兑换 </cl-button>
  205. </view>
  206. </cl-popup>
  207. <cl-popup v-model="visible4" showClose :show-header="false" direction="center" :pt="{
  208. inner: {
  209. className: '!bg-transparent'
  210. }
  211. }">
  212. <view class="w-[360px] relative">
  213. <image src="https://oss.xiaoxiongcode.com/static/home/6171.png" mode="widthFix"
  214. class="w-[360px] relative ">
  215. </image>
  216. <view class=" wz-1 ">
  217. 您当前未绑定微信,是否绑定微信?
  218. </view>
  219. <view class="wz-2 " @tap="handleClosePopup1">
  220. 绑定
  221. </view>
  222. <view class="wz-3 " @tap="handleClosePopup2">
  223. 取消
  224. </view>
  225. </view>
  226. </cl-popup>
  227. <Physics v-if="selected === 'physics'" />
  228. <Chinese v-else-if="selected === 'chinese'" />
  229. <English v-else-if="selected === 'english'" />
  230. <Mix v-else-if="selected === 'mix'" />
  231. <Game v-else-if="selected === 'game'" />
  232. <Exchange v-else-if="selected === 'exchange'" />
  233. <MathModal v-else-if="selected === 'math'" />
  234. </cl-page>
  235. </template>
  236. <style lang="scss" scoped>
  237. .wz-1 {
  238. @apply absolute text-black text-[18px] font-bold w-[330px] text-center;
  239. line-height: 40px;
  240. left: 50%;
  241. transform: translateX(-50%);
  242. top: 48%;
  243. }
  244. .wz-2 {
  245. @apply absolute bottom-[12px] text-white text-[18px] font-bold text-center;
  246. right: 31%;
  247. bottom: 17%;
  248. }
  249. .wz-3 {
  250. @apply absolute bottom-[12px] text-white text-[18px] font-bold text-center;
  251. left: 26%;
  252. bottom: 17%;
  253. }
  254. .menus {
  255. @apply mt-[3vh] mx-auto rounded-[20px];
  256. }
  257. .selected {
  258. @apply scale-[1.1] bg-[#efefef99] rounded-xl;
  259. font-weight: bold;
  260. }
  261. .text-stroke {
  262. text-shadow:
  263. -1px -1px 0 #000,
  264. 1px -1px 0 #000,
  265. -1px 1px 0 #000,
  266. 1px 1px 0 #000;
  267. }
  268. .check {
  269. background: linear-gradient(0deg, #FBD00E 0%, #FBEC92 100%);
  270. }
  271. </style>