shuxue.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. <template>
  2. <view class="ezy-study-page ezy-shuxue-study-page">
  3. <view class="study-school-year" @click="clickGradeTerm">{{gradeTerm}}</view>
  4. <view class="ezy-study-wrap">
  5. <view class="chapter-box" @click="handleCheckCatalogue">{{options.numberStr}}</view>
  6. <view @click="handleCheckCatalogue" :class="getTitleClass(options.zhangName)">
  7. {{getZhangName(options.zhangName)}}
  8. </view>
  9. <!-- 动物类型 -->
  10. <view v-if="growthType!=null" :class="currentGrowth()"></view>
  11. <view>
  12. <!-- 小岛 -->
  13. <view class="brand-item" v-for="(item, index) in options.jieList" :key="item.jieId"
  14. @click="listClick(item, index,options)" :class="getClass(options,index,isVip,item)">
  15. <view v-if="isVip === 'VIP'">
  16. <!-- 序号 -->
  17. <view class="brand-icon" v-if="item.studyFlag===0">{{ item.number }}</view>
  18. <!-- 星星 -->
  19. <view class="brand-finish-icon" v-if="item.studyFlag===1"></view>
  20. <!-- 箭头 -->
  21. <view v-if="item.daeFlag &&animalNum == index" class="brand-arrow"></view>
  22. <!-- 节名称 -->
  23. <view class="brand-content">{{ item.jieName }}</view>
  24. </view>
  25. <view v-if="isVip == 'Not-Vip'">
  26. <!-- 序号或锁 -->
  27. <view class="brand-icon">{{ item.number }}
  28. </view>
  29. <view v-if="item.firstFlag !=1" class="brand-lock"></view>
  30. <!-- 箭头 -->
  31. <view v-if="item.daeFlag && animalNum == index &&isVip != 'Visitor'" class="brand-arrow">
  32. </view>
  33. <!-- 节名称 -->
  34. <view class="brand-content"> {{ item.jieName }} </view>
  35. </view>
  36. <view v-if="isVip == 'Visitor' && appleTishen =='true'&&item.type!=2">
  37. <!-- 锁 -->
  38. <view class="brand-icon">{{ item.number }}
  39. </view>
  40. <!-- 节名称 -->
  41. <view class="brand-content"> {{ item.jieName }} </view>
  42. </view>
  43. <view v-if="isVip == 'Visitor'&& appleTishen =='false'">
  44. <!-- 锁 -->
  45. <view class="brand-icon">{{ item.number }}
  46. </view>
  47. <!-- 锁 -->
  48. <view v-if="item.firstFlag !=1" class="brand-lock"></view>
  49. <!-- 箭头 -->
  50. <view v-if="item.daeFlag && animalNum == index &&isVip != 'Visitor'" class="brand-arrow">
  51. </view>
  52. <!-- 节名称 -->
  53. <view class="brand-content"> {{ item.jieName }} </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script setup>
  61. import {
  62. reactive,
  63. ref,
  64. watch,
  65. getCurrentInstance,
  66. onMounted,
  67. nextTick
  68. } from "vue";
  69. import cacheManager from "@/utils/cacheManager.js";
  70. import {
  71. toast,
  72. getUserIdentity
  73. } from "@/utils/common";
  74. import {
  75. onShow
  76. } from '@dcloudio/uni-app';
  77. const growthType = ref(null);
  78. const appleTishen = ref(null);
  79. const $emit = defineEmits(['clickGradeTerm', 'onLeft', 'onRight', 'handleCheckCatalogue', 'listClick'])
  80. const props = defineProps({
  81. options: {
  82. type: Object,
  83. },
  84. youkeImage: {
  85. String: '',
  86. },
  87. gradeTerm: {
  88. type: String,
  89. },
  90. })
  91. onShow(() => {
  92. growthType.value = cacheManager.get('auth') ? cacheManager.get('auth').growthType : props.youkeImage
  93. appleTishen.value = cacheManager.get('youkeTishen').toString()
  94. console.log(appleTishen.value);
  95. })
  96. const isVip = getUserIdentity();
  97. //console.log('isVip', isVip);
  98. const gradeMapping = {
  99. 1: '一年级',
  100. 2: '二年级',
  101. 3: '三年级',
  102. 4: '四年级',
  103. 5: '五年级',
  104. 6: '六年级'
  105. };
  106. const termMapping = {
  107. 1: ' 数学',
  108. 2: ' 英语'
  109. };
  110. let startX = ref(0);
  111. let isSliding = ref(false);
  112. let endX = ref(0);
  113. let gradeTerm = ref('');
  114. let animalNum = ref(0);
  115. function clickGradeTerm() {
  116. $emit('clickGradeTerm');
  117. }
  118. function listClick(data, index, data2) {
  119. data.daeFlag = true
  120. nextTick(() => {
  121. animalNum.value = index
  122. })
  123. setTimeout(() => {
  124. $emit('listClick', data, data2, index);
  125. }, 300)
  126. }
  127. // 获取章name
  128. function getZhangName(data) {
  129. if (data.length <= 9) {
  130. return data
  131. } else {
  132. return getZhangContent(data);
  133. }
  134. }
  135. function currentGrowth(data) {
  136. if (growthType.value == 0) {
  137. return 'animal-img dan-img'
  138. } else if (growthType.value == 1) {
  139. return 'animal-img xiao-e-img'
  140. } else if (growthType.value == 2) {
  141. return 'animal-img zhong-e-img'
  142. } else {
  143. return 'animal-img da-e-img'
  144. }
  145. }
  146. // 章换行显示
  147. function getZhangContent(data) {
  148. let length = data.length;
  149. // 初始将字符串平分成两半
  150. let halfLength = Math.floor(length / 2);
  151. // 插入换行符
  152. let firstLine = data.slice(0, halfLength);
  153. let secondLine = data.slice(halfLength);
  154. //console.log(firstLine + '\n' + secondLine, 'firstLine + + secondLine');
  155. return firstLine + '\n' + secondLine;
  156. }
  157. // 章class
  158. function getTitleClass(data) {
  159. if (data.length <= 5) {
  160. return 'chapter-title-box chapter-small-title-box'
  161. } else if (data.length <= 9) {
  162. return 'chapter-title-box chapter-middle-title-box'
  163. } else if (data.length > 9) {
  164. return 'chapter-title-box chapter-big-title-box'
  165. }
  166. }
  167. // 获取节class
  168. function getClass(data, index, isVip, item) {
  169. // console.log('data',data);
  170. let brandActive = '';
  171. if (isVip === 'VIP') {
  172. brandActive = 'brand-active';
  173. } else if (data.number == 1 && item.firstFlag == 1 && isVip == 'Not-Vip') {
  174. brandActive = 'brand-active';
  175. } else if (appleTishen.value =='true'&&isVip == 'Visitor') {
  176. brandActive = 'brand-active';
  177. } else if (data.number == 1 && item.firstFlag == 1 && isVip == 'Visitor' && item.type == 1) {
  178. brandActive = 'brand-active';
  179. } else {
  180. brandActive = '';
  181. }
  182. let indexLast = data.jieList.length - 1;
  183. // 用于苹果审核 游客模式 去掉单元测试
  184. if(appleTishen.value =='true' && isVip == 'Visitor'){
  185. // 判断最后一个为名称是否为单元测试,是单元测试则返回ceshi-jie
  186. if (index === indexLast && data.jieList[data.jieList.length - 1].jieName == '单元测试') {
  187. return '';
  188. } else {
  189. return getJieClass(data, index, brandActive)
  190. }
  191. }else{
  192. // 判断最后一个为名称是否为单元测试,是单元测试则返回ceshi-jie
  193. if (index === indexLast && data.jieList[data.jieList.length - 1].jieName == '单元测试') {
  194. return 'ceshi-brand-item' + ' ' + brandActive;
  195. } else {
  196. return getJieClass(data, index, brandActive)
  197. }
  198. }
  199. }
  200. // 根据获取节字数获取class
  201. function getJieClass(data, index, active) {
  202. let itemJieName = data.jieList[index].jieName.length;
  203. if (itemJieName > 7) {
  204. return 'big-brand-item' + ' ' + active;
  205. } else {
  206. return 'small-brand-item' + ' ' + active;
  207. }
  208. }
  209. function handleCheckCatalogue() {
  210. if(appleTishen.value =='true'&&isVip =='Visitor'){
  211. return false
  212. }
  213. $emit('handleCheckCatalogue');
  214. }
  215. function onTouchStart(event) {
  216. console.log(event.touches.length);
  217. isSliding.value = false
  218. if (event.touches.length === 1) {
  219. isSliding.value = true;
  220. startX.value = event.touches[0].pageX;
  221. } else {
  222. isSliding.value = false;
  223. event.preventDefault()
  224. return
  225. }
  226. }
  227. function onSwipeLeft(event) {
  228. console.log('11111');
  229. if (cacheManager.get('auth')) {
  230. $emit('onLeft');
  231. }
  232. }
  233. function onSwipeRight(event) {
  234. console.log('22222');
  235. console.log(cacheManager.get('auth'));
  236. if (cacheManager.get('auth')) {
  237. console.log('啊啊啊啊啊');
  238. $emit('onRight');
  239. }
  240. }
  241. function onTouchEnd(event) {
  242. if (isSliding.value) {
  243. const distanceX = event.changedTouches[0].clientX - startX.value
  244. if (distanceX > 200) {
  245. onSwipeLeft();
  246. } else if (distanceX < -200) {
  247. onSwipeRight();
  248. }
  249. isSliding.value = false
  250. } else {
  251. console.log('error');
  252. }
  253. }
  254. function dataRecom(data) {
  255. const index = data.jieList.findIndex(item => item.studyFlag == 0);
  256. if (index !== -1) {
  257. data.jieList[index].daeFlag = true;
  258. animalNum.value = index
  259. }
  260. }
  261. watch(() => props.options, (newVal, oldVal) => {
  262. // console.log('New options:', newVal);
  263. // console.log('Old options:', oldVal);
  264. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  265. dataRecom(newVal)
  266. }, {
  267. deep: true,
  268. immediate: true
  269. });
  270. watch(() => props.gradeTerm, (newVal, oldVal) => {
  271. // console.log('New options:', newVal);
  272. // console.log('Old options:', oldVal);
  273. // 在这里可以根据新的 options 做一些操作,比如发起请求等
  274. gradeTerm.value = newVal
  275. }, {
  276. deep: true,
  277. immediate: true
  278. });
  279. </script>
  280. <style>
  281. </style>