index.vue 15 KB

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