123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- <template >
- <view>
- <u-toast ref="uToast" />
- <u-loading :show="false"></u-loading>
- <u-modal v-model="show" :content="content" :confirm-text="confirmtext?confirmtext:'确定'" @confirm="confirmBtn" :title="title?title:'提示'"></u-modal>
- <u-modal v-model="show2" :show-cancel-button="true" :content="content" :confirm-text="confirmtext?confirmtext:'确定'" :cancel-text="canceltext?canceltext:'取消'" @confirm="confirmBtn" @cancel="cancelBtn" :title="title?title:'提示'"></u-modal>
-
- <u-navbar v-if="mytitle" :title="mytitle" :is-back="noback" :border-bottom="!noback">
- <view class="slot-wrap"></view>
- </u-navbar>
- <view v-show="false" :login="islogin()" ></view>
-
- </view>
- </template>
- <script>
- import * as API from '@/apis/common.js'
- import * as API_WeiXin from '@/apis/weixin.js'
- import * as API_user from '@/apis/user.js'
-
- import {
- getUrlParam,
- getWeixinRedirectURI,
- isWeiXin
- } from '@/utils'
- export default {
- name:"Common",
- props:{
- login: {
- require: false,
- default: false,
- },
- noback:{
- require: false,
- default: true,
- },
- mytitle: {
- require: false,
- default: false,
- },
- },
- data() {
- return {
-
- isloginBl:true,
- show:false,
- show2:false,
- fnc:null,
- fncCancel:null,
- fncBl:false,
- content:null,
- confirmtext:null,
- title:null,
- canceltext:null,
- };
-
- },methods:{
-
- getOpenId() {
- const code = getUrlParam('code');
-
- if (!code) {
- var url = document.URL;
-
- window.location.href = getWeixinRedirectURI(process.car.VUE_APP_WXAPPID, url);
- } else {
-
-
- API_WeiXin.getDataByCode(code).then(response => {
- var openId=response.data.openid;
- this.carhelp.setOpenId(response.data.openid)
- //var linkUrl = document.URL.replace(/\?code=(.*?)&state=STATE/g, '');
- //window.location = linkUrl; //隐藏参数
- //return Promise.resolve(response.openid);
- this.$emit("myOpenId")
- this.getLogin(openId)
-
- }).catch(error => {
- console.log(error);
- });
-
- }
-
- },
- getLogin(openId){
-
- if(this.login){
-
- API_user.findByOpenId({
- openId:openId
- }).then(response2 => {
-
-
- if(response2.data){
- var token = response2.data ? response2.data.token : '';
- this.carhelp.setToken(token);
- this.carhelp.setPersonInfo(response2.data.token)
-
- this.$emit("myLogin")
- // uni.switchTab({
- // url: '/pages/index/index'
- // });
- }
-
- }).catch(error => {
-
- console.log(error);
- uni.reLaunch({
- url: '/pages/index/login'
- })
- })
- }
- },
- islogin(){
- if(!this.carhelp.getOpenId()){
- this.getOpenId();
- }else{
-
- }
- if(this.login&&this.carhelp.getOpenId()){
- this.getLogin(this.carhelp.getOpenId());
- }
-
- },
- goError(message){
- this.setFnc(function(){
- uni.switchTab({
- url: '/pages/index/index'
- });
- })
- this.alert2(message?message:'访问链接异常','前往首页')
-
- },
- setFnc(fnc,fncCancel){
-
- this.fnc=fnc;
- this.fncCancel=fncCancel;
- this.fncBl=true
- },
- alert2(content,confirmtext,title){
- this.show=true;
- this.content=content;
- this.confirmtext=confirmtext;
- this.title=title;
- uni.hideLoading();
- },
- confirm(content,confirmtext,title,canceltext){
- this.show2=true;
- this.content=content;
- this.confirmtext=confirmtext;
- this.canceltext=canceltext;
- this.title=title;
- uni.hideLoading();
- },
- cancelBtn(){
- if(this.fncCancel){
- this.fncCancel()
- this.fncBl=false;
- }
- },
- confirmBtn(){
-
- if(this.fncBl){
- this.fnc()
- this.fncBl=false;
- }
- },
- showLoading(bl,message){
- if(bl==null ||bl){
- // request 要改同步改
- uni.showLoading({
- mask:true,title:'加载中...'
- })
- }else{
- uni.hideLoading();
- if(message){
- this.alert(message)
- }
- }
-
- },
- alert(message,fnc){
-
- this.$refs.uToast.show({
- title: message,
- type:'default',
- position:'bottom',
- callback:fnc
- })
- }
- },mounted(){
-
- },destroyed(){
-
- }
-
- }
- </script>
- <style>
- .navbar-right {
- display: flex;
- margin-right: 20rpx;
- span{
- color:rgb(96, 98, 102);
- margin-left: 3px;
- }
- }
- .slot-wrap {
- display: flex;
- align-items: center;
- flex: 1;
- }
- </style>
|