index.vue 9.7 KB

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