home.uvue 9.8 KB

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