index-index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  1. <template>
  2. <view class="index-index">
  3. <custom-nav class="title" :title="title" ref="ltm" noback @rTap="rTap">
  4. <text class="cuIcon-question"></text>
  5. </custom-nav>
  6. <view v-if="logged" class="content">
  7. <view class="area manage">
  8. <navigator v-for="(item, index) in namageList" :url="item.url" :key="index">
  9. <image :src="item.image"></image>
  10. <text>{{ item.name }}</text>
  11. </navigator>
  12. </view>
  13. <view class="area swiper">
  14. <swiper :autoplay="true" :circular="true" :interval="3456" :duration="345">
  15. <swiper-item v-for="(item, index) in swiper" :key="index" @tap="toSwiperDetail(index)">
  16. <image :src="item.imgurl"></image>
  17. </swiper-item>
  18. </swiper>
  19. </view>
  20. <view class="area news">
  21. <image src="../../static/index/index/news.png"></image>
  22. <view class="hot">热点</view>
  23. <swiper :vertical="true" :autoplay="true" :circular="true" :interval="3456" :duration="345">
  24. <swiper-item class="ellipsis" v-for="(item, index) in news" :key="index">
  25. {{ item.contents}}
  26. </swiper-item>
  27. </swiper>
  28. </view>
  29. <view class="area kingkong">
  30. <navigator v-for="(item, index) in kingkongList" :url="item.url" :key="index">
  31. <image :src="item.image"></image>
  32. <text>{{ item.name }}</text>
  33. </navigator>
  34. </view>
  35. <view class="area article">
  36. <view class="area-name">
  37. <text class="border"></text>
  38. <text>常来微聊</text>
  39. </view>
  40. <view class="article-body" @tap="toDetail">
  41. <image class="left" :src="article.imgurl[0]"></image>
  42. <view class="right">
  43. <view class="title ellipsis">{{ article.title || '' }}</view>
  44. <view class="des">{{ article.summary || '' }}...</view>
  45. <view class="time-auth">
  46. <view class="time">{{ article.created_at | formatTime }}</view>
  47. <view class="auth">发布人:{{ article.author || '' }}</view>
  48. </view>
  49. </view>
  50. </view>
  51. <view @tap="toMore" class="more-article">显示更多<text class="cuIcon-right"></text></view>
  52. </view>
  53. </view>
  54. <view v-else class="login-btn" style="height: 100%;">
  55. <navigator open-type="reLaunch" url="../../pages/login-reg/login-reg">登录/注册</navigator>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import { _API_IndexIndex, _API_AppUpdata, _API_DownLoadNewVersion } from '@/apis/app.js'
  61. import { _API_GetUserStatus, _API_GetUserInfo, _API_ConfireLevel } from '@/apis/user.js'
  62. export default {
  63. data() {
  64. return {
  65. title: '首页',
  66. namageList: [
  67. {
  68. name: '订单管理',
  69. url: '../../pages/manage-order/manage-order',
  70. image: '../../static/index/index/manage-order.png'
  71. },
  72. {
  73. name: '人员管理',
  74. url: '../../pages/manage-people/manage-people',
  75. image: '../../static/index/index/manage-poeple.png'
  76. },
  77. {
  78. name: '财富管理',
  79. url: '../../pages/manage-money/manage-money',
  80. image: '../../static/index/index/manage-money.png'
  81. }
  82. ],
  83. news: {},
  84. swiper: [],
  85. article: {},
  86. kingkongList: [
  87. {
  88. name: '订货下单',
  89. url: '../../pages/place-order/place-order',
  90. image: '../../static/index/index/place-order.png'
  91. },
  92. {
  93. name: '我的订单',
  94. url: '../../pages/my-order/my-order',
  95. image: '../../static/index/index/my-order.png'
  96. },
  97. {
  98. name: '下级订单',
  99. url: '../../pages/down-order/down-order',
  100. image: '../../static/index/index/down-order.png'
  101. },
  102. {
  103. name: '我的库存',
  104. url: '../../pages/my-storage/my-storage',
  105. image: '../../static/index/index/my-stock.png'
  106. },
  107. {
  108. name: '邀请代理',
  109. url: '../../pages/invite-proxy/invite-proxy',
  110. image: '../../static/index/index/invite-proxy.png'
  111. },
  112. {
  113. name: '注册审核',
  114. url: '../../pages/register-examine/register-examine',
  115. image: '../../static/index/index/register-examine.png'
  116. },
  117. {
  118. name: '我的邀请',
  119. url: '../../pages/my-invite/my-invite',
  120. image: '../../static/index/index/my-invite.png'
  121. },
  122. {
  123. name: '团队管理',
  124. url: '../../pages/team-manage/team-manage',
  125. image: '../../static/index/index/team-manage.png'
  126. }
  127. ]
  128. }
  129. },
  130. computed: {
  131. userinfo() { return this.$store.state.userinfo }, // 用户信息
  132. screenWidth() { return this.$store.state.device.screenWidth }, // 屏幕宽
  133. logged() { return this.$store.state.app.token ? true : false}, // 用户是否登录
  134. screenHeight() { return this.$store.state.device.screenHeight }, // 屏幕高
  135. },
  136. mounted() { // 页面创建后判断用户状态
  137. uni.$on('RELAUNCH', () => uni.reLaunch({ url: '../login-reg/login-reg' })) // 监听 token 失效事件,跳转到登录页
  138. if (this.$store.state.app.token) { // 当用户处于登陆状态
  139. _API_GetUserStatus().then(res => { // 获取用户状态
  140. this.$store.commit('userinfo/UPDATA_USERINFO', res.data) // 获取用户状态后保存在 vuex 中
  141. if (res.data.status == 1) { // 用户状态为 1 表示正常
  142. if (res.data.cert_status == 0) { // 用户认证状态为 0 表示 已注册 未填写信息
  143. this.indexRequest() // 请求首页数据
  144. // 等待闪屏结束后弹出身份验证弹窗
  145. uni.HIDESCREENED ? this.showAuth() : uni.$on('HIDESCREEN', () => this.showAuth())
  146. } else if (res.data.cert_status > 0 && res.data.cert_status < 6) { // 用户为认证状态
  147. uni.reLaunch({ url: '../auth-progress/auth-progress' }) // 跳转到用户认证进度页面
  148. } else if (res.data.cert_status == 6) { // 用户认证完成
  149. this.indexRequest() // 请求首页数据
  150. _API_GetUserInfo().then(res => { // 请求用户信息
  151. this.$store.commit('userinfo/UPDATA_USERINFO', res.data) // 获取用户信息后保存在 vuex 中
  152. // 等待闪屏结束后判断用户等级是否发生改变
  153. uni.HIDESCREENED ? this.isLevelChanged(res) : uni.$on('HIDESCREEN', () => this.isLevelChanged(res))
  154. })
  155. this.$store.dispatch('message/getMessage') // 获取系统消息 // 获取系统消息 // 获取系统消息 // 获取系统消息 // 获取系统消息 // 获取系统消息
  156. }
  157. } else if (res.data.status == 0) { // 用户状态为 0 表示用户已被冻结
  158. this.$store.commit('app/LOGOUT')
  159. this.$refs.ltm.modal('提示', ['您已退出大卫博士'], 'noCancle').then(() => {
  160. uni.reLaunch({ url: '../login-reg/login-reg' })
  161. })
  162. }
  163. })
  164. }
  165. },
  166. onPullDownRefresh() { // 下拉刷新
  167. this.indexRequest()
  168. },
  169. methods: {
  170. rTap() { uni.navigateTo({ url: '../help-use/help-use' }) }, // 点击导航栏帮助
  171. toSwiperDetail(index) { // 点击轮播图
  172. if (this.swiper[index].is_jump == 1) {
  173. uni.navigateTo({ url: `../app-webview/app-webview?url=${this.swiper[index].url}` })
  174. }
  175. },
  176. toDetail() { // 点击首页文章
  177. if (this.article.id) {
  178. uni.navigateTo({ url: '/pages/article-detail/article-detail?fromIndex=1' })
  179. }
  180. },
  181. toMore() { // 点击文章查看更多
  182. uni.setStorageSync('_INDEXARTICLETAP', '_INDEXARTICLETAP') // 利用本地存储传参
  183. uni.switchTab({ url: '../index-commu/index-commu' })
  184. },
  185. indexRequest() { // 请求首页数据
  186. _API_IndexIndex().then(res => {
  187. uni.stopPullDownRefresh()
  188. this.news = res.data.news
  189. this.swiper = res.data.swiper,
  190. this.article = res.data.article
  191. this.$store.commit('article/ADDINDEX', this.article)
  192. })
  193. },
  194. showAuth() { // 弹出身份验证弹窗
  195. uni.AUTH = this.getNativeObj('/static/icon/auth-float.png', 1, 576/696)
  196. uni.AUTH.addEventListener('click', () => { // 点击弹窗跳转到身份验证页面
  197. uni.reLaunch({ url: '../auth-identity/auth-identity' })
  198. })
  199. uni.AUTH.show()
  200. },
  201. showLevelChanged() { // 根据用户等级一级变化情况弹出相应提示
  202. let LEVELCHANGED;
  203. return new Promise(resolve => {
  204. if (this.userinfo.level == '皇冠代理') {
  205. if (+this.userinfo.level_change == 1) { // 升为皇冠
  206. LEVELCHANGED = this.getNativeObj('/static/icon/upToCrown.png', 2, 576/676)
  207. }
  208. } else if (this.userinfo.level == '顶级代理') {
  209. if (+this.userinfo.level_change == 1) { // 升为顶级
  210. LEVELCHANGED = this.getNativeObj('/static/icon/upToTop.png', 2, 576/676)
  211. } else if (+this.userinfo.level_change == -1) { // 降为顶级
  212. LEVELCHANGED = this.getNativeObj('/static/icon/downToTop.png', 2, 576/676)
  213. }
  214. } else if (this.userinfo.level == '特级代理') {
  215. if (+this.userinfo.level_change == -1) { // 降为特级
  216. LEVELCHANGED = this.getNativeObj('/static/icon/downToSuper.png', 2, 576/676)
  217. }
  218. }
  219. LEVELCHANGED.addEventListener('click', e => { // 点击弹等级变动弹窗确认等级变动
  220. if (this.isClickInArea(e, 576/676)) {
  221. resolve(); // 用户确认等级变动
  222. LEVELCHANGED.hide() // 隐藏等级变动弹窗
  223. }
  224. })
  225. LEVELCHANGED.show()
  226. })
  227. },
  228. isLevelChanged(res) { // 检测用户等级是否发生变化
  229. if (+res.data.level_change == 0) { // 如果用户等级没有变化
  230. this.upData() // 检查更新
  231. } else { // 如果用户等级发送变化,等待用户确认等级变化后再检查更新
  232. this.showLevelChanged().then(() => {
  233. _API_ConfireLevel() // 用户确认等级变动请求
  234. this.upData() // 检查更新
  235. })
  236. }
  237. },
  238. upData() { // app 检查更新
  239. _API_AppUpdata().then(res => { // 获取更新链接
  240. if (res.data.version !== this.$store.state.app.version) { // 有新版本 /////////////////////////////
  241. const position = this.getNativeObjPosition(560/681)
  242. const pn = this.getNativeObjPosition(560/681)
  243. Object.keys(pn).forEach(key => pn[key] = Number(pn[key].split('px')[0]))
  244. const UPDATA = new plus.nativeObj.View('auth', // 定义升级弹窗
  245. { top:'0px', left:'0px', height:'100%', width:'100%', backgroundColor: "rgba(0, 0 , 0, 0.6)" },
  246. [
  247. { tag:'img', id:'authImg', src: '/static/icon/appupdata.png', position },
  248. { tag:'font', id:'font1', text:'版本号:' + res.data.version,
  249. textStyles:{ size: '18px', align: 'left', whiteSpace: 'normal', verticalAlign: 'top' },
  250. position:{ top: pn.top+pn.height/2-18+'px', left: pn.left+20+'px', width: '100%', height: '36px' },
  251. },
  252. {
  253. tag:'font',
  254. id:'font2',
  255. text:res.data.message,
  256. textStyles:{ size: '16px', align: 'left', whiteSpace: 'normal', verticalAlign: 'top', overflow: 'ellipsis' },
  257. position:{ top: pn.top+pn.height/2+14 + 'px', left: pn.left+30+ 'px', width: pn.width-60 + 'px', height: pn.height/4 + 'px' },
  258. },
  259. ],
  260. )
  261. UPDATA.addEventListener('click', e => { // 点击弹窗升级app
  262. if (this.isClickInArea(e, 560/681)) { // 如果点击图片区
  263. UPDATA.close() // 关闭弹窗
  264. this.$refs.ltm.modal('提示', ['新版本将在后台下载', '下载成功后会提示您安装'], 'noCancle').then(() => { // 提示后台下载
  265. uni.UPDATING = true // 标记 app 正在下载状态 为 true
  266. uni.UPDATAPROGRESS = 0 // 设置 app 下载进度为 0
  267. const downloadTask = _API_DownLoadNewVersion(res.data.url) // 发送请求
  268. downloadTask.onProgressUpdate((e) => uni.UPDATAPROGRESS = e.progress ) // 更新进度
  269. downloadTask.then(({ tempFilePath }) => { // app 下载成功后弹窗通知
  270. uni.UPDATING = false // 标记 app 正在下载状态 为 false
  271. uni.$emit('UPDATAAPP', tempFilePath) // 通知弹窗弹出
  272. } )
  273. })
  274. } else { // 如果点击背景区
  275. UPDATA.close()
  276. }
  277. })
  278. UPDATA.show() // 弹出升级弹窗
  279. }
  280. })
  281. },
  282. getNativeObj(src, id, as) { // 绘制透明背景弹窗
  283. return new plus.nativeObj.View('alert' + id,
  284. { top:'0px', left:'0px', height:'100%', width:'100%', backgroundColor: "rgba(0, 0 , 0, 0.6)" },
  285. [{tag:'img', id:'alertImg' + id, src, position: this.getNativeObjPosition(as) }],
  286. )
  287. },
  288. getNativeObjPosition(as) { // 获取透明背景弹窗图片区位置
  289. const width = this.screenWidth * 0.8
  290. const height = width / as
  291. const top = (this.screenHeight - height) / 2
  292. const left = (this.screenWidth - width) / 2
  293. return {
  294. width: Math.floor(width) + 'px',
  295. height: Math.floor(height) + 'px',
  296. top: Math.floor(top) + 'px',
  297. left: Math.floor(left) + 'px'
  298. }
  299. },
  300. isClickInArea(e, as) { // 检测点击透明背景弹窗是否为图片区
  301. let p = this.getNativeObjPosition(as)
  302. Object.keys(p).forEach(key => p[key] = Number(p[key].split('px')[0]))
  303. if ((e.pageX >= p.left) && (e.pageX <= (p.left + p.width)) && (e.pageY >= p.top) && (e.pageY <= (p.top + p.height))) {
  304. return true
  305. }
  306. }
  307. }
  308. }
  309. </script>
  310. <style lang="scss" scoped>
  311. .index-index {
  312. @include page();
  313. .title {
  314. .cuIcon-question {
  315. font-size: 38rpx;
  316. margin-right: 30rpx;
  317. }
  318. }
  319. .content {
  320. .area {
  321. background: #FFFFFF;
  322. &.manage {
  323. height: 170rpx;
  324. display: flex;
  325. navigator {
  326. flex: 1;
  327. height: 100%;
  328. display: flex;
  329. align-items: center;
  330. flex-direction: column;
  331. image {
  332. width: 94rpx;
  333. height: 94rpx;
  334. margin-top: 20rpx;
  335. }
  336. text {
  337. font-size:32rpx;
  338. margin-top: 10rpx;
  339. }
  340. }
  341. }
  342. &.swiper {
  343. height: 250rpx;
  344. margin-top: 12rpx;
  345. swiper {
  346. height: 100%;
  347. image {
  348. width: 100%;
  349. height: 100%;
  350. }
  351. }
  352. }
  353. &.news {
  354. display: flex;
  355. height: 50rpx;
  356. padding: 10rpx 30rpx;
  357. box-sizing: border-box;
  358. image {
  359. height: 100%;
  360. width: 180rpx;
  361. }
  362. .hot {
  363. @include flex();
  364. width: 72rpx;
  365. height: 100%;
  366. font-size: 24rpx;
  367. margin-left: 10rpx;
  368. border-radius: 4rpx;
  369. color: $app-base-color;
  370. border:1px solid $app-base-color;
  371. }
  372. swiper {
  373. flex: 1;
  374. height: 100%;
  375. font-size: 26rpx;
  376. margin-left: 20rpx;
  377. }
  378. }
  379. &.article {
  380. margin-top: 10rpx;
  381. .area-name {
  382. @include flex();
  383. height: 72rpx;
  384. font-size: 32rpx;
  385. padding: 0 30rpx;
  386. box-sizing: border-box;
  387. justify-content: flex-start;
  388. border-bottom: 1rpx solid $app-base-bg;
  389. .border {
  390. width: 6rpx;
  391. height: 30rpx;
  392. margin-right: 16rpx;
  393. background: $app-base-color;
  394. }
  395. }
  396. .article-body {
  397. @include flex();
  398. height: 200rpx;
  399. padding: 10rpx 30rpx;
  400. box-sizing: border-box;
  401. .left {
  402. width: 180rpx;
  403. height: 180rpx;
  404. margin-right: 30rpx;
  405. border-radius: 10rpx;
  406. }
  407. .right {
  408. @include flex(column);
  409. flex: 1;
  410. height: 100%;
  411. align-items: flex-start;
  412. justify-content: space-between;
  413. .title {
  414. width: 444rpx;
  415. font-size: 32rpx;
  416. }
  417. .des {
  418. flex: 1;
  419. width: 100%;
  420. margin: 2rpx 0;
  421. font-size: 24rpx;
  422. overflow: scroll;
  423. }
  424. .time-auth {
  425. @include flex();
  426. width: 100%;
  427. font-size: 24rpx;
  428. color: $app-sec-text-color;
  429. justify-content: space-between;
  430. }
  431. }
  432. }
  433. .more-article {
  434. @include flex();
  435. height: 72rpx;
  436. font-size: 26rpx;
  437. border-top: 1rpx solid $app-base-bg;
  438. }
  439. }
  440. }
  441. }
  442. }
  443. </style>