index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <view class="content">
  3. <!-- 导航 -->
  4. <view class="nav">
  5. <view class="leftView" @click="back">
  6. <image v-if="type == 'app'" src="../../static/mobile/backBtn.png" mode=""
  7. style="width: 22rpx; height: 40rpx; padding-left: 24rpx;"></image>
  8. </view>
  9. <view class="navTitle">门店学院</view>
  10. <view class="rightView">
  11. <image src="../../static/mobile/icona_fenlei@2x.png" mode="" class="rightImg" @click="goSift"></image>
  12. <image src="../../static/mobile/icon_search@2x.png" mode="" class="rightImg" style="margin-left: 40rpx;"
  13. @click="goSearch"></image>
  14. </view>
  15. </view>
  16. <!-- 推荐 -->
  17. <view class="commend" v-if="bannerArr.length != 0">
  18. <view class="top">
  19. <image src="../../static/mobile/icon_tuijian@2x.png" mode="" style="width: 28rpx; height: 28rpx;">
  20. <text class="tuijian">推荐文章</text>
  21. </image>
  22. </view>
  23. <!-- item -->
  24. <view class="scrollBg">
  25. <scroll-view scroll-x="true" @scroll="scroll">
  26. <view class="itemBg">
  27. <view v-for="(item,index) in bannerArr" :key="index" class="item" @click="goDetail(item)">
  28. <image :src="item.logoImg" mode="" class="swpImg"></image>
  29. <view class="title">{{item.title}}</view>
  30. <view style="display: flex;">
  31. <view class="title2" @click.stop="goTuijianTab(item)">{{item.categoryName}}</view>
  32. </view>
  33. </view>
  34. </view>
  35. </scroll-view>
  36. </view>
  37. </view>
  38. <!-- 分类 -->
  39. <view v-for="(item,index) in itemArr" :key="index">
  40. <view class="fenleiBg">
  41. <!-- 头 -->
  42. <view class="fenTop" :class="{fenTopNo:item.children == 0}">
  43. <view class="leftTop">
  44. <view class="tuijian">{{item.name}}</view>
  45. <view class="sum">共{{item.count}}篇文章</view>
  46. </view>
  47. <view class="rightTop">
  48. <view class="allBtn" @click="goTopTab(item)">查看全部
  49. <image src="../../static/mobile/icon_arrow@2x.png" mode=""
  50. style="width: 11rpx; height: 18rpx; margin-left: 10rpx;"></image>
  51. </view>
  52. </view>
  53. </view>
  54. <!-- item -->
  55. <view class="itemBg">
  56. <view v-for="(item2,index2) in item.children" :key="index2" v-if="index2<2" class="twoItem"
  57. @click="goList(item2)">
  58. <image :src="item2.logoImg" mode="" class="img2"></image>
  59. <view class="itemTitle">{{item2.title}}</view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <!-- 下拉菜单 -->
  65. <view class="sift" v-show="showSift" @click="goHide()">
  66. <view class="siftItemBg">
  67. <view v-for="(item,index) in siftData" :key="index" class="siftItem">
  68. <view @click="goTopTab(item)">{{item.name}}</view>
  69. </view>
  70. </view>
  71. </view>
  72. <view class="gotop" @click="gotoTop">
  73. <image src="../../static/pcimg/btn_top@2x.png" mode="" class="gotopImg"></image>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. export default {
  79. data() {
  80. return {
  81. bannerArr: [],
  82. scrollTop: 0,
  83. old: {
  84. scrollTop: 0
  85. },
  86. itemArr: [],
  87. showSift: false,
  88. siftData: [],
  89. type: '',
  90. }
  91. },
  92. onLoad(opt) {
  93. this.getDetailData()
  94. this.getSiftData()
  95. this.type = opt.type
  96. if (this.type) {
  97. uni.setStorage({
  98. key: 'userType',
  99. data: this.type,
  100. success: function() {
  101. }
  102. });
  103. }
  104. },
  105. methods: {
  106. back() {
  107. console.log('type', this.type);
  108. if (this.type == "app") {
  109. var standalone = window.navigator.standalone
  110. var userAgent = window.navigator.userAgent.toLowerCase()
  111. var safari = /safari/.test(userAgent)
  112. var ios = /iphone|ipod|ipad|mac/.test(userAgent)
  113. var android = /android/.test(userAgent)
  114. if (ios) {
  115. if (true) { //!standalone&& !safari
  116. window.webkit.messageHandlers.goMyNav.postMessage(null)
  117. }
  118. } else if (android) {
  119. window.android.postMessage()
  120. }
  121. } else {
  122. uni.navigateBack({
  123. })
  124. }
  125. },
  126. gotoTop() {
  127. uni.pageScrollTo({
  128. scrollTop: 0,
  129. duration: 300
  130. });
  131. },
  132. goHide() {
  133. this.showSift = false
  134. },
  135. goDetail(item) {
  136. uni.navigateTo({
  137. url: 'detail?id=' + item.id
  138. })
  139. },
  140. goTuijianTab(item) {
  141. uni.navigateTo({
  142. url: 'topTab?topCode=' + item.categoryCode + '&comment=' + item.comment + '&topName=' + item
  143. .categoryName
  144. })
  145. },
  146. goList(item) {
  147. // 1分类2文章
  148. if (item.type == 1) {
  149. uni.navigateTo({
  150. url: 'list?topCode=' + item.code + '&comment=' + item.comment + '&topName=' + item.name
  151. })
  152. }
  153. if (item.type == 2) {
  154. uni.navigateTo({
  155. url: 'detail?id=' + item.id
  156. })
  157. }
  158. },
  159. goTopTab(item) {
  160. this.showSift = false
  161. uni.navigateTo({
  162. url: 'topTab?topCode=' + item.code + '&comment=' + item.comment + '&topName=' + item.name
  163. })
  164. },
  165. goSift() {
  166. this.showSift = !this.showSift
  167. },
  168. goSearch() {
  169. uni.navigateTo({
  170. url: 'search'
  171. })
  172. },
  173. scroll: function(e) {
  174. console.log(e)
  175. this.old.scrollTop = e.detail.scrollTop
  176. },
  177. goNav(urlStr) {
  178. uni.navigateTo({
  179. url: urlStr
  180. })
  181. },
  182. getDetailData() {
  183. uni.showLoading({
  184. title: '加载中'
  185. })
  186. let url = '/trainingOpenApiV2/indexData',
  187. params = {
  188. }
  189. this.$http(url, params, 'GET').then(res => {
  190. uni.hideLoading();
  191. var data = res.data
  192. // 处理 undefined和null转为空白字符串
  193. for (const key in data) {
  194. data[key] = this.$praseStrEmpty(data[key])
  195. }
  196. this.detailData = data
  197. this.bannerArr = this.detailData.recommendList
  198. this.itemArr = this.detailData.categoryList
  199. })
  200. },
  201. getSiftData() {
  202. uni.showLoading({
  203. title: '加载中'
  204. })
  205. let url = '/trainingOpenApiV2/allCategory',
  206. params = {
  207. }
  208. this.$http(url, params, 'GET').then(res => {
  209. uni.hideLoading();
  210. var data = res.data
  211. // 处理 undefined和null转为空白字符串
  212. for (const key in data) {
  213. data[key] = this.$praseStrEmpty(data[key])
  214. }
  215. this.siftData = data
  216. })
  217. },
  218. // 下拉刷新 上拉加载更多
  219. onPullDownRefresh() {
  220. // this.page = 1;
  221. // this.getItemData()
  222. this.getDetailData()
  223. setTimeout(function() {
  224. uni.stopPullDownRefresh();
  225. }, 1000);
  226. },
  227. // onReachBottom() {
  228. // this.page++;
  229. // this.getItemData()
  230. // },
  231. }
  232. }
  233. </script>
  234. <style scoped>
  235. .content {
  236. min-height: 100vh;
  237. background-color: #f4f5f7;
  238. padding-top: 88rpx;
  239. padding-bottom: 20rpx;
  240. }
  241. .nav {
  242. position: fixed;
  243. left: 0;
  244. top: 0;
  245. width: 100vw;
  246. height: 88rpx;
  247. background-color: #FFFFFF;
  248. display: flex;
  249. justify-content: space-between;
  250. align-items: center;
  251. z-index: 999;
  252. border-bottom: #eeeeee 2rpx solid;
  253. }
  254. .navTitle {
  255. font-size: 36rpx;
  256. font-weight: bold;
  257. color: #3c3c3c;
  258. }
  259. .leftView {
  260. width: 30%;
  261. }
  262. .rightView {
  263. width: 30%;
  264. display: flex;
  265. justify-content: flex-end;
  266. padding-right: 24rpx;
  267. }
  268. .rightImg {
  269. width: 40rpx;
  270. height: 40rpx;
  271. }
  272. .commend {
  273. background-color: #FFFFFF;
  274. margin: 20rpx 0;
  275. padding: 30rpx 25rpx;
  276. }
  277. .top {
  278. padding-bottom: 24rpx;
  279. }
  280. .tuijian {
  281. font-size: 32rpx;
  282. font-weight: bold;
  283. color: #3c3c3c;
  284. margin-left: 10rpx;
  285. }
  286. .scrollBg {
  287. background-color: #FFFFFF;
  288. }
  289. .scroll-view {
  290. white-space: nowrap;
  291. }
  292. .itemBg {
  293. display: flex;
  294. }
  295. .item {
  296. width: 398rpx;
  297. margin-right: 25rpx;
  298. }
  299. .swpImg {
  300. border-radius: 10rpx;
  301. width: 398rpx;
  302. height: 224rpx;
  303. }
  304. .title {
  305. font-size: 28rpx;
  306. color: #3c3c3c;
  307. /* 隐藏文字显示 ...不换行 */
  308. overflow: hidden;
  309. text-overflow: ellipsis;
  310. white-space: nowrap;
  311. margin: 14rpx 0;
  312. }
  313. .itemTitle {
  314. font-size: 28rpx;
  315. color: #3c3c3c;
  316. /* 隐藏文字显示 ...不换行 */
  317. overflow: hidden;
  318. text-overflow: ellipsis;
  319. white-space: nowrap;
  320. margin-top: 14rpx;
  321. }
  322. .title2 {
  323. background: rgba(63, 144, 247, 0.1);
  324. font-size: 22rpx;
  325. color: #3F90F7;
  326. height: 36rpx;
  327. line-height: 36rpx;
  328. border-radius: 18rpx;
  329. padding: 3rpx 14rpx;
  330. min-width: 0;
  331. max-width: 138rpx;
  332. margin-bottom: 10rpx;
  333. text-align: center;
  334. /* 隐藏文字显示 ...不换行 */
  335. overflow: hidden;
  336. text-overflow: ellipsis;
  337. white-space: nowrap;
  338. }
  339. .fenleiBg {
  340. background-color: #FFFFFF;
  341. margin: 20rpx 0;
  342. padding: 30rpx 25rpx;
  343. }
  344. .fenTop {
  345. padding-bottom: 24rpx;
  346. display: flex;
  347. justify-content: space-between;
  348. align-items: center;
  349. }
  350. .fenTopNo {
  351. padding-bottom: 0;
  352. display: flex;
  353. justify-content: space-between;
  354. align-items: center;
  355. }
  356. .leftTop {
  357. display: flex;
  358. align-items: center;
  359. }
  360. .allBtn {
  361. font-size: 24rpx;
  362. color: #999999;
  363. }
  364. .sum {
  365. font-size: 24rpx;
  366. color: #999999;
  367. margin-left: 16rpx;
  368. }
  369. .twoItem {
  370. width: 339rpx;
  371. margin-right: 25rpx;
  372. }
  373. .img2 {
  374. width: 339rpx;
  375. height: 191rpx;
  376. border-radius: 10rpx;
  377. border: #EEEEEE 2rpx solid;
  378. }
  379. .sift {
  380. position: fixed;
  381. left: 0;
  382. top: 88rpx;
  383. width: 100vw;
  384. min-height: 100vh;
  385. background-color: rgba(0, 0, 0, 0.4);
  386. }
  387. .siftItemBg {
  388. background-color: #FFFFFF;
  389. width: 100%;
  390. height: 500rpx;
  391. overflow-y: scroll;
  392. }
  393. .siftItem {
  394. background-color: #FFFFFF;
  395. color: #333333;
  396. font-size: 30rpx;
  397. text-align: center;
  398. padding: 30rpx 0;
  399. }
  400. .gotopImg {
  401. width: 100rpx;
  402. height: 100rpx;
  403. }
  404. .gotop {
  405. position: fixed;
  406. right: 15rpx;
  407. bottom: 100rpx;
  408. cursor: pointer;
  409. }
  410. </style>