index.vue 17 KB

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