index.vue 9.2 KB

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