home.uvue 11 KB

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