index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. <template>
  2. <!-- <page-meta :page-font-size="`${this.scaleFontSize}px`" :root-font-size="`${this.scaleFontSize}px`"></page-meta> -->
  3. <view class="content">
  4. <image class="bg-img" v-show="template == 'homeIndex'" src="@/static/image/home/home_top_bg.png"></image>
  5. <image class="bg-img" v-show="template == 'watchIndex'" src="@/static/image/hall/home_top_bg.png"></image>
  6. <view class="grace-page-header" :style="{ background: headerBG }">
  7. <image class="bg-img" v-show="template == 'watchIndex'" src="@/static/image/hall/home_top_bg.png"></image>
  8. <!-- 沉浸式状态栏 -->
  9. <view class="content-header" id="gracePageHeader" :style="{ minHeight: headerHeight + 'px', height: headerHeight + 'px', overflow: 'hidden' }">
  10. <view class="content-header-l">
  11. <u-tabs
  12. :list="list"
  13. :current="current"
  14. lineHeight="8rpx"
  15. :lineColor="current==1?'#2583EB':'rgba(255, 255, 255, 0)'"
  16. :activeStyle="{color:current==1?'#2583EB':'#fff',fontWeight: '400',fontSize: '40rpx',}"
  17. :inactiveStyle="{color:current==1?'#2583EB':'#fff'}"
  18. @click="changeTemplate"></u-tabs>
  19. </view>
  20. <!-- <indexSubsection ref="indexSubsection" @onChange="changeTemplate" /> -->
  21. <view class="content-header-r">
  22. <!-- <view @click="showQidai()">
  23. <image src="@/static/image/home1/weixin_icon.png" mode="aspectFill"></image>
  24. <text>分享</text>
  25. </view>
  26. <view @click="goToMsg()">
  27. <image v-show="template=='homeIndex'" src="@/static/image/home1/new_icon.png" mode="aspectFill"></image>
  28. <image v-show="template=='watchIndex'" src="@/static/image/home/message1.png" mode="aspectFill"></image>
  29. <text :class="template=='homeIndex'?'es-c-white':'es-c-33'">消息</text>
  30. </view> -->
  31. <view class="x-ac" style="height: auto; display: block">
  32. <image v-show="template == 'homeIndex'" style="margin-right: 10px" src="@/static/image/home1/scancode.png" mode="aspectFill" @click="handleScan()"></image>
  33. <!-- <image v-show="template == 'homeIndex'" src="@/static/images/service_center_icon_white.png" mode="aspectFill" @click="goToWXMsg()"></image>
  34. <image
  35. v-show="template == 'watchIndex'"
  36. style="margin-left: 50rpx"
  37. src="@/static/image/my/service_center_icon.png"
  38. mode="aspectFill"
  39. @click="goToWXMsg()"
  40. ></image> -->
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <!-- 新手指引 -->
  46. <!-- <template v-if="template == 'homeIndex'">
  47. <myGuide ref="myGuide" :step="step"></myGuide>
  48. </template> -->
  49. <!-- homeIndex -->
  50. <!-- pages_watch -->
  51. <view v-show="template == 'homeIndex'">
  52. <homeIndex ref="homeIndex" />
  53. </view>
  54. <view v-show="template == 'watchIndex'">
  55. <watchIndex ref="watchIndex" />
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. import store from '@/store';
  61. import indexSubsection from '@/components/indexSubsection/indexSubsection';
  62. import homeIndex from './components/homeIndex.vue';
  63. import watchIndex from './components/watchIndex.vue';
  64. import { getLocation } from '@/api/index.js';
  65. // #ifdef APP-PLUS
  66. import permision1 from '@/utils/permission.js';
  67. import { premissionCheck } from '@/js_sdk/wa-permission/permission.js';
  68. const idCode = uni.requireNativePlugin('Ba-IdCode');
  69. // #endif
  70. // const idCode = uni.requireNativePlugin('Ba-IdCode')
  71. export default {
  72. components: {
  73. indexSubsection,
  74. homeIndex,
  75. watchIndex
  76. },
  77. data() {
  78. return {
  79. list: [{
  80. name: '首页',
  81. template: 'homeIndex',
  82. }
  83. // ,{
  84. // name: '健康',
  85. // template: 'watchIndex',
  86. // }
  87. ],
  88. current: 0,
  89. template: 'homeIndex', // homeIndex:首页 , watchIndex: 腕表页面
  90. option: '',
  91. top: 0,
  92. statusBarBG: 'none',
  93. headerHeight: 44,
  94. locCity: '中康未来',
  95. scaleFontSize: uni.getStorageSync('fontSize'),
  96. step: {
  97. name: 'indexguide',
  98. guideList: [
  99. {
  100. el: '',
  101. tips: '上下滑动,了解中康未来',
  102. next: ''
  103. }
  104. // ,{
  105. // el: '#indexguide1',
  106. // tips: '药膳、经络、疾病医学百科知识快速查询',
  107. // next: '下一步',
  108. // },{
  109. // el: '#indexguide2',
  110. // tips: '权威医生、药师实时在线咨询',
  111. // next: '下一步',
  112. // },{
  113. // el: '#indexguide3',
  114. // tips: '免费健康自测,了解自身健康情况',
  115. // next: '下一步',
  116. // },{
  117. // el: '#indexguide4',
  118. // childEl: ".indexguide4-child",
  119. // tips: '购买健康疗法享健康',
  120. // next: '完成',
  121. // },
  122. ]
  123. }
  124. };
  125. },
  126. onPageScroll(e) {
  127. if (this.template == 'homeIndex') {
  128. this.top = e.scrollTop;
  129. }
  130. },
  131. computed: {
  132. // 计算属性的 getter
  133. headerBG() {
  134. if (this.template == 'homeIndex') {
  135. var top = this.top / 88;
  136. return 'rgba(37, 131, 235, ' + top + ')';
  137. }
  138. }
  139. },
  140. onLoad(option) {
  141. // #ifdef APP-PLUS
  142. if (plus.runtime.isAgreePrivacy()) {
  143. const guide = uni.getStorageSync(this.step.name);
  144. if (!!guide) {
  145. //permision1.checkPush();
  146. }
  147. //this.doGetLocation();
  148. }
  149. // #endif
  150. let that = this;
  151. uni.setNavigationBarTitle({
  152. title: that.$qconfig.appName
  153. });
  154. uni.setStorageSync('indexTemplate', 0);
  155. this.option = option;
  156. this.scaleFontSize = store.state.timStore.fontSize;
  157. uni.$on('loginOut', function() {
  158. let IMUserID = uni.getStorageSync('IMUserID');
  159. //Igexin.unbindAlias(IMUserID);
  160. uni.removeStorage({key: "IMUserID"});
  161. uni.setStorageSync("AppToken",null);
  162. uni.removeStorage({ key: 'IMToken' });
  163. uni.removeStorageSync("onLaunch",null)
  164. uni.removeStorageSync("imUnread",null);
  165. uni.removeStorageSync("companyUser");
  166. uni.removeStorageSync("CompanyUserToken");
  167. uni.$emit("refreshUserInfo");
  168. let pages = getCurrentPages();
  169. let url = pages[ pages.length - 1]; //当前页页面实例
  170. //如果登录界面已打开,自动关闭
  171. if(url!=undefined&&url.route=="pages/auth/loginIndex"){
  172. return;
  173. }
  174. uni.reLaunch({
  175. url: '/pages/auth/loginIndex'
  176. });
  177. });
  178. // this.$nextTick(()=>{
  179. // this.$refs[this.template].initLoad(this.option)
  180. // })
  181. },
  182. onReady() {
  183. this.$refs.indexSubsection?.selectorQuery();
  184. this.$refs[this.template].initReady();
  185. },
  186. onShow() {
  187. // #ifdef APP-PLUS
  188. if (plus.runtime.isAgreePrivacy()) {
  189. if (plus.runtime.channel == 'baidu') {
  190. let bdCmdType = uni.getStorageSync('bdCmdType');
  191. if (this.$isEmpty(bdCmdType)) {
  192. this.$registerIdCode('activate', 0, 0);
  193. }
  194. }
  195. }
  196. // #endif
  197. if (!this.$isLogin()) {
  198. uni.navigateTo({
  199. url: '/pages/auth/loginIndex'
  200. });
  201. } else {
  202. this.$updateMsgDot();
  203. }
  204. this.$nextTick(() => {
  205. this.$refs[this.template].initShow();
  206. });
  207. },
  208. methods: {
  209. changeTemplate(e) {
  210. this.current = e.index
  211. const tem = this.current== 1 ? 'watchIndex' : 'homeIndex';
  212. if (this.template == tem) return;
  213. this.template = tem;
  214. uni.pageScrollTo({
  215. scrollTop: 0,
  216. duration: 100
  217. });
  218. this.$nextTick(() => {
  219. //this.$refs[this.template].initLoad(this.option)
  220. this.$refs[this.template].initReady();
  221. this.$refs[this.template].initShow();
  222. });
  223. },
  224. registerIdCode() {
  225. //注册,先注册再获取,注意APP合规性,若最终用户未同意隐私政策则不要调用
  226. idCode.register((res) => {
  227. console.log(res);
  228. });
  229. },
  230. async getLocation() {
  231. let status;
  232. // #ifdef APP-PLUS
  233. status = await this.checkPermission();
  234. if (status !== 1) {
  235. return;
  236. }
  237. // #endif
  238. // #ifdef MP-WEIXIN || MP-TOUTIAO || MP-QQ
  239. status = await this.getSetting();
  240. if (status === 2) {
  241. this.showConfirm();
  242. return;
  243. }
  244. // #endif
  245. this.doGetLocation();
  246. },
  247. doGetLocation() {
  248. getLocation().then((res) => {
  249. this.locCity = res.city.replace(/市|区/g, '');
  250. });
  251. },
  252. getSetting: function () {
  253. return new Promise((resolve, reject) => {
  254. uni.getSetting({
  255. success: (res) => {
  256. if (res.authSetting['scope.userLocation'] === undefined) {
  257. resolve(0);
  258. return;
  259. }
  260. if (res.authSetting['scope.userLocation']) {
  261. resolve(1);
  262. } else {
  263. resolve(2);
  264. }
  265. }
  266. });
  267. });
  268. },
  269. openSetting: function () {
  270. this.hideConfirm();
  271. uni.openSetting({
  272. success: (res) => {
  273. if (res.authSetting && res.authSetting['scope.userLocation']) {
  274. this.doGetLocation();
  275. }
  276. },
  277. fail: (err) => {}
  278. });
  279. },
  280. async checkPermission() {
  281. let status = permision1.isIOS ? await permision1.requestIOS('location') : await permision1.requestAndroid('android.permission.ACCESS_FINE_LOCATION');
  282. if (status === null || status === 1) {
  283. status = 1;
  284. } else if (status === 2) {
  285. uni.showModal({
  286. content: '系统定位已关闭',
  287. confirmText: '确定',
  288. showCancel: false,
  289. success: function (res) {}
  290. });
  291. } else if (status.code) {
  292. uni.showModal({
  293. content: status.message
  294. });
  295. } else {
  296. uni.showModal({
  297. content: '需要定位权限',
  298. confirmText: '设置',
  299. success: function (res) {
  300. if (res.confirm) {
  301. permision1.gotoAppSetting();
  302. }
  303. }
  304. });
  305. }
  306. return status;
  307. },
  308. showQidai() {
  309. uni.showToast({ title: '功能完善中,敬请期待...', icon: 'none' });
  310. },
  311. goToMsg() {
  312. uni.switchTab({
  313. url: '/pages_im/pages/conversation/conversationList/index'
  314. });
  315. },
  316. async goToWXMsg() {
  317. const url = getApp().globalData.kfurl; //企业微信客服链接
  318. const corpId = getApp().globalData.corpId; //企业id
  319. // #ifdef H5
  320. window.location.href = url;
  321. // #endif
  322. // #ifdef MP-WEIXIN
  323. wx.openCustomerServiceChat({
  324. extInfo: {
  325. url
  326. },
  327. corpId,
  328. success(res) {
  329. console.log('成功');
  330. },
  331. fail(err) {
  332. console.log(err, '报错');
  333. }
  334. });
  335. // #endif
  336. // #ifdef APP-PLUS
  337. let shares = await this.getAppShare().catch((err) => {
  338. throw Error(err);
  339. });
  340. shares['weixin'].openCustomerServiceChat(
  341. {
  342. corpid: corpId,
  343. url
  344. },
  345. (suc) => {
  346. console.log('客服打开成功', JSON.stringify(res));
  347. },
  348. (err) => {
  349. console.log('error', JSON.stringify(err));
  350. }
  351. );
  352. // #endif
  353. },
  354. getAppShare() {
  355. // #ifdef APP-PLUS
  356. return new Promise((re, rj) => {
  357. let shares = null;
  358. var pusher = plus.share.getServices(
  359. function (s) {
  360. shares = {};
  361. s.forEach((e) => (shares[e.id] = e));
  362. re(shares);
  363. },
  364. function (e) {
  365. rj(e);
  366. }
  367. );
  368. });
  369. // #endif
  370. },
  371. getIdCodes() {
  372. //获取设备的各种标识码
  373. idCode.getIdCodes((res) => {
  374. if (res.data) {
  375. //this.msgList.unshift(JSON.stringify(res.data));
  376. let ua = plus.navigator.getUserAgent();
  377. console.log('qxj ua:' + ua);
  378. console.log('qxj getIdCodes:' + JSON.stringify(res.data));
  379. }
  380. });
  381. },
  382. getOAID() {
  383. //异步获取 OAID
  384. idCode.getOAID((res) => {
  385. if (res.data) {
  386. //this.msgList.unshift(JSON.stringify(res.data));
  387. console.log('qxj getOAID:' + JSON.stringify(res.data));
  388. }
  389. });
  390. },
  391. //扫码
  392. async handleScan() {
  393. // #ifdef APP-PLUS
  394. uni.navigateTo({
  395. url: '/pages_watch/healthMonitoring/scanCode?typeFun=getIndexScanCode'
  396. });
  397. // #endif
  398. // #ifdef MP-WEIXIN
  399. this.checkWXCamera();
  400. // #endif
  401. },
  402. scanQRCode() {
  403. const that = this;
  404. uni.scanCode({
  405. success(res) {
  406. if (res.result) {
  407. // 扫描成功,处理二维码内容
  408. console.log('扫描结果:', res.result);
  409. const scanInfo = res.result;
  410. if (scanInfo && scanInfo.indexOf('http://userapp.zkhj6.com/bindcompanyuser') > -1) {
  411. const companyUserId = this.getUrlParam(scanInfo).companyUserId;
  412. console.log('扫描结果公司码:', companyUserId);
  413. this.$handleBindCompanyFsUser(companyUserId);
  414. }
  415. } else {
  416. // 扫描失败
  417. uni.showToast({
  418. title: '扫描失败',
  419. icon: 'none'
  420. });
  421. }
  422. },
  423. fail() {}
  424. });
  425. },
  426. getUrlParam(url) {
  427. const queryStr = url.split('?')[1];
  428. if (!queryStr) {
  429. return {};
  430. }
  431. const params = queryStr.split('&');
  432. const queryParams = {};
  433. params.forEach((param) => {
  434. const [key, value] = param.split('=');
  435. queryParams[key] = value;
  436. });
  437. return queryParams;
  438. },
  439. checkWXCamera() {
  440. const that = this;
  441. uni.getSetting({
  442. success(res) {
  443. // 判断是否拥有此权限进行拉起授权 和 重新授权功能
  444. if (!res.authSetting['scope.camera']) {
  445. // 未授权此项权限 拉起授界面
  446. uni.authorize({
  447. scope: 'scope.camera',
  448. success() {
  449. // 授权成功后 就可以执行 需要权限的 操作函数了
  450. // 使用已授权的功能
  451. that.scanQRCode();
  452. },
  453. fail(err) {
  454. /*
  455. 第一次拒绝授权后必须在 uni.authorize的fail中使用
  456. uni.openSetting 才能进入设置界面打开授权按钮
  457. */
  458. uni.showToast({
  459. title: '您拒绝了授权',
  460. icon: 'none'
  461. });
  462. // 这里必须经过一个confirm 不然也会出现问题(啥问题我也不知道)
  463. uni.showModal({
  464. title: '是否重新授权相机功能',
  465. success(res) {
  466. if (res.confirm) {
  467. uni.openSetting({
  468. success() {
  469. console.log('开启权限成功');
  470. },
  471. fail() {
  472. console.log('开启权限失败');
  473. }
  474. });
  475. } else if (res.cancel) {
  476. console.log('拒绝开启开启权限');
  477. }
  478. }
  479. });
  480. }
  481. });
  482. } else {
  483. that.scanQRCode();
  484. }
  485. }
  486. });
  487. }
  488. }
  489. };
  490. </script>
  491. <style lang="scss" scoped>
  492. @mixin u-flex($flexD, $alignI, $justifyC) {
  493. display: flex;
  494. flex-direction: $flexD;
  495. align-items: $alignI;
  496. justify-content: $justifyC;
  497. }
  498. .nav-bar {
  499. background-color: red;
  500. // background-image: url("@/static/image/home/home_top_bg.png");
  501. // background-repeat: no-repeat;
  502. // background-size: 100%;
  503. // background-color: #F4F7FA;
  504. // position: absolute;
  505. // width: 100%;
  506. // height: 524rpx;
  507. }
  508. .content {
  509. width: 100%;
  510. box-sizing: border-box;
  511. // overflow: hidden;
  512. // margin-top: var(--status-bar-height);
  513. // padding-top: 24rpx;
  514. font-family: PingFang SC, PingFang SC;
  515. font-weight: 400;
  516. font-size: 24rpx;
  517. color: #999999;
  518. // background-image: url("@/static/image/home/home_top_bg.png");
  519. background-repeat: no-repeat;
  520. background-size: 100%;
  521. // box-sizing: border-box;
  522. // padding-top: calc(var(--status-bar-height) + 24rpx);
  523. // padding-bottom: var(--window-bottom);
  524. // font-family: PingFang SC, PingFang SC;
  525. // font-weight: 400;
  526. // font-size: 24rpx;
  527. // color: #999999;
  528. position: relative;
  529. z-index: 2;
  530. .bg-img {
  531. position: absolute;
  532. width: 100%;
  533. height: 524rpx;
  534. top: 0;
  535. left: 0;
  536. right: 0;
  537. bottom: 0;
  538. z-index: 0;
  539. }
  540. .bgConent {
  541. background-image: url('@/static/image/home/home_top_bg.png');
  542. background-repeat: no-repeat;
  543. background-size: 100%;
  544. background-color: #f4f7fa;
  545. position: absolute;
  546. width: 100%;
  547. height: 524rpx;
  548. top: 0;
  549. left: 0;
  550. right: 0;
  551. bottom: 0;
  552. z-index: 0;
  553. }
  554. .grace-page-header {
  555. position: fixed;
  556. width: 100%;
  557. left: 0;
  558. top: 0;
  559. z-index: 98;
  560. border-bottom: 0px solid #ffffff;
  561. padding-top: calc(var(--status-bar-height));
  562. box-sizing: border-box;
  563. overflow: hidden;
  564. }
  565. .content-header {
  566. height: 80rpx;
  567. padding: 0 24rpx;
  568. @include u-flex(row, center, space-between);
  569. position: relative;
  570. z-index: 2;
  571. &-l {
  572. font-family: PingFang SC, PingFang SC;
  573. font-weight: 500;
  574. font-size: 26rpx;
  575. color: #ffffff;
  576. line-height: 28rpx;
  577. @include u-flex(row, center, flex-start);
  578. .address {
  579. width: 38rpx;
  580. height: 38rpx;
  581. margin-right: 6rpx;
  582. }
  583. .arrow_down {
  584. width: 24rpx;
  585. height: 24rpx;
  586. margin-left: 8rpx;
  587. }
  588. }
  589. &-r {
  590. @include u-flex(row, center, flex-start);
  591. view {
  592. font-family: PingFang SC, PingFang SC;
  593. font-weight: 400;
  594. font-size: 22rpx;
  595. color: #ffffff;
  596. line-height: 24rpx;
  597. @include u-flex(column, center, space-between);
  598. // width: 80rpx;
  599. // height: 80rpx;
  600. padding-top: 2rpx;
  601. padding-bottom: 6rpx;
  602. }
  603. image {
  604. width: 40rpx;
  605. height: 40rpx;
  606. }
  607. }
  608. }
  609. }
  610. .indexSubsection {
  611. position: fixed;
  612. top: calc(var(--status-bar-height) + 24rpx);
  613. left: 50%;
  614. transform: translateX(-50%);
  615. z-index: 9999;
  616. height: 88rpx;
  617. line-height: 88rpx;
  618. display: inline-flex;
  619. flex-direction: column;
  620. align-items: center;
  621. justify-content: center;
  622. }
  623. </style>