|
@@ -8,24 +8,17 @@
|
|
|
* 三端首页必须先进,公共页面的common组件不要写role,三端专属页面一定要写相应的role
|
|
|
* =============================================================================
|
|
|
*/
|
|
|
- import * as API_WeiXin from '@/apis/weixin'
|
|
|
- import * as API_Student from '@/apis/student'
|
|
|
- import * as API_Teacher from '@/apis/teacher'
|
|
|
- import * as API_Control from '@/apis/control'
|
|
|
- import * as API_Control_Business from '@/apis/controlBusiness'
|
|
|
- import * as API_Common from '@/apis/common'
|
|
|
- import {
|
|
|
- weixinAppId,
|
|
|
- } from '@/config'
|
|
|
+ import * as API_WeiXin from '$project/apis/weixin'
|
|
|
import {
|
|
|
getUrlParam,
|
|
|
- getWeixinRedirectURI
|
|
|
- } from '@/utils'
|
|
|
+ getWeixinRedirectURI,
|
|
|
+ isWeiXin
|
|
|
+ } from '$project/utils'
|
|
|
import {
|
|
|
mapGetters,
|
|
|
mapMutations
|
|
|
} from 'vuex'
|
|
|
- import * as types from '@/store/mutation-types'
|
|
|
+ import * as types from '$project/store/mutation-types'
|
|
|
export default {
|
|
|
name: 'Common',
|
|
|
components: {},
|
|
@@ -42,13 +35,11 @@
|
|
|
}
|
|
|
},
|
|
|
data() {
|
|
|
- return {
|
|
|
- //isLoading: true,
|
|
|
- }
|
|
|
+ return {}
|
|
|
},
|
|
|
created() {
|
|
|
//公共组件的执行方法放在created中执行,父组件的create放在motuned中执行
|
|
|
- if (global.IS_WEIXIN) {
|
|
|
+ if (isWeiXin()) {
|
|
|
if (this.checkOpenId) {
|
|
|
if (!this.openId) {
|
|
|
this.getOpenid();
|
|
@@ -58,10 +49,9 @@
|
|
|
}
|
|
|
} else {
|
|
|
if (this.checkOpenId) {
|
|
|
- this.mui.alert('请使用微信浏览打开!', '提示', function() {
|
|
|
+ mui.alert('请使用微信浏览打开!', '提示', function() {
|
|
|
//info.innerText = '你刚关闭了警告框';
|
|
|
});
|
|
|
- //this.mui.toast('请使用微信浏览打开');
|
|
|
}
|
|
|
}
|
|
|
},
|
|
@@ -70,7 +60,7 @@
|
|
|
getOpenid() {
|
|
|
const code = getUrlParam('code');
|
|
|
if (!code) {
|
|
|
- window.location.href = getWeixinRedirectURI(weixinAppId, document.URL);
|
|
|
+ window.location.href = getWeixinRedirectURI(process.env.VUE_APP_WXAPPID, document.URL);
|
|
|
} else {
|
|
|
console.log(code);
|
|
|
|
|
@@ -105,248 +95,48 @@
|
|
|
},
|
|
|
//角色判定调用不同的信息获取详情
|
|
|
getDataByOpenId() {
|
|
|
- if (this.role == 'student') {
|
|
|
- this.set_now_role('student');
|
|
|
- this.getStudentByOpenId();
|
|
|
- } else if (this.role == 'teacher') {
|
|
|
- this.set_now_role('teacher');
|
|
|
- this.getTeacherByOpenId();
|
|
|
- } else if (this.role == 'control') {
|
|
|
- this.set_now_role('control');
|
|
|
- this.getControlByOpenId();
|
|
|
- } else if (this.role == 'control_merchant') {
|
|
|
- this.set_now_role('control_merchant');
|
|
|
- this.getControlBusinessByOpenId();
|
|
|
- } else {
|
|
|
- //this.mui.toast('角色不存在');
|
|
|
- //异步回调父组件的方法-无角色的时候仍要操作保证获取到了openid
|
|
|
- this.asynCallBack();
|
|
|
- }
|
|
|
- },
|
|
|
- //获取学生用户详情,初始用户没有这些信息会在添加学生信息成功时返回
|
|
|
- getStudentByOpenId(type) {
|
|
|
- var type = type || '';
|
|
|
- API_Student.getDataByOpenId(this.openId).then(response => {
|
|
|
- //console.log(response)
|
|
|
-
|
|
|
- var token = response ? response.token : '';
|
|
|
- //if (response.token !== undefined) {
|
|
|
- this.set_token(token);
|
|
|
- //}
|
|
|
- //如果有当前用户则去获取未读系统消息数
|
|
|
- if (type != 'scene') {
|
|
|
- if (token) {
|
|
|
- this.getSystemMessageNum();
|
|
|
- } else {
|
|
|
- //异步回调父组件的方法
|
|
|
- this.asynCallBack();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- var personInfo = response ? response.personInfo : '';
|
|
|
- //if (response.personInfo !== undefined) {
|
|
|
- this.set_student_person_data(personInfo);
|
|
|
- //}
|
|
|
-
|
|
|
- var parentId = response ? response.parentId : '';
|
|
|
- //if (response.parentId !== undefined) {
|
|
|
- this.set_student_parent_id(parentId);
|
|
|
- //}
|
|
|
-
|
|
|
- var currentInfo = response ? response.currentInfo : '';
|
|
|
- //if (response.currentInfo !== undefined) {
|
|
|
- this.set_student_current_info(currentInfo);
|
|
|
- //}
|
|
|
-
|
|
|
- if (type == 'scene') {
|
|
|
- this.$emit('callBack');
|
|
|
- }
|
|
|
-
|
|
|
- }).catch(error => {
|
|
|
- this.mui.toast(error);
|
|
|
- })
|
|
|
+ this.getUserInfoByOpenId();
|
|
|
},
|
|
|
- //获取老师用户详情,
|
|
|
- getTeacherByOpenId(type) {
|
|
|
+ //获取用户详情
|
|
|
+ getUserInfoByOpenId() {
|
|
|
var type = type || '';
|
|
|
- API_Teacher.getDataByOpenId(this.openId).then(response => {
|
|
|
+ API_WeiXin.getDataByOpenId(this.openId).then(response => {
|
|
|
//console.log(response)
|
|
|
|
|
|
var token = response ? response.token : '';
|
|
|
- //if (response.token !== undefined) {
|
|
|
this.set_token(token);
|
|
|
- //}
|
|
|
- //如果有当前用户则去获取未读系统消息数
|
|
|
- if (type != 'scene') {
|
|
|
- if (token) {
|
|
|
- this.getSystemMessageNum();
|
|
|
- } else {
|
|
|
- //异步回调父组件的方法
|
|
|
- this.asynCallBack();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
var person = response ? response.person : '';
|
|
|
- //if (response.person !== undefined) {
|
|
|
- this.set_teacher_person_data(person);
|
|
|
- //}
|
|
|
+ this.set_person_data(person);
|
|
|
|
|
|
var company = response ? response.company : '';
|
|
|
- //if (response.company !== undefined) {
|
|
|
- this.set_teacher_company_data(company);
|
|
|
- //}
|
|
|
-
|
|
|
- var role = response ? response.identityList : [];
|
|
|
- this.set_teacher_role(role);
|
|
|
- //如果有一个角色,则设置默认当前角色
|
|
|
- if (role.length == 1) {
|
|
|
- this.set_now_teacher_role(role[0]);
|
|
|
- }
|
|
|
-
|
|
|
- if (type == 'scene') {
|
|
|
- this.$emit('callBack');
|
|
|
- }
|
|
|
-
|
|
|
- }).catch(error => {
|
|
|
- this.mui.toast(error);
|
|
|
- })
|
|
|
- },
|
|
|
- //获取监管端用户详情,
|
|
|
- getControlByOpenId() {
|
|
|
- API_Control.getDataByOpenId(this.openId).then(response => {
|
|
|
- //console.log(response)
|
|
|
-
|
|
|
- var token = response ? response.token : '';
|
|
|
- this.set_token(token);
|
|
|
-
|
|
|
-
|
|
|
- //类型1学校2商户
|
|
|
- var type = response ? response.type : '';
|
|
|
- this.set_control_type_data(type);
|
|
|
+ this.set_company_data(company);
|
|
|
|
|
|
-
|
|
|
- //如果有当前用户则去获取未读系统消息数
|
|
|
- if (token) {
|
|
|
- if (type == '1') {
|
|
|
- this.getSystemMessageNum();
|
|
|
- } else {
|
|
|
- //异步回调父组件的方法
|
|
|
- this.asynCallBack();
|
|
|
- }
|
|
|
- } else {
|
|
|
- //异步回调父组件的方法
|
|
|
- this.asynCallBack();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- var person = response ? (response.hasOwnProperty('person') ? response.person : '') : '';
|
|
|
- this.set_control_person_data(person);
|
|
|
-
|
|
|
- var company = response ? (response.hasOwnProperty('company') ? response.company : '') : '';
|
|
|
- this.set_control_company_data(company);
|
|
|
-
|
|
|
- var merchant = response ? (response.hasOwnProperty('merchant') ? response.merchant : '') : '';
|
|
|
- this.set_control_merchant_data(merchant);
|
|
|
-
|
|
|
- }).catch(error => {
|
|
|
- this.mui.toast(error);
|
|
|
- })
|
|
|
- },
|
|
|
- //获取监管端商户详情,
|
|
|
- getControlBusinessByOpenId() {
|
|
|
- API_Control_Business.getDataByOpenId(this.openId).then(response => {
|
|
|
- //console.log(response)
|
|
|
-
|
|
|
- var token = response ? response.token : '';
|
|
|
- this.set_token(token);
|
|
|
-
|
|
|
-
|
|
|
- //类型1学校2商户
|
|
|
- var type = response ? response.type : '';
|
|
|
- this.set_control_type_data(type);
|
|
|
-
|
|
|
-
|
|
|
- //如果有当前用户则去获取未读系统消息数
|
|
|
- if (token) {
|
|
|
- if (type == '1') {
|
|
|
- this.getSystemMessageNum();
|
|
|
- } else {
|
|
|
- //异步回调父组件的方法
|
|
|
- this.asynCallBack();
|
|
|
- }
|
|
|
- } else {
|
|
|
- //异步回调父组件的方法
|
|
|
- this.asynCallBack();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- var person = response ? (response.hasOwnProperty('person') ? response.person : '') : '';
|
|
|
- this.set_control_person_data(person);
|
|
|
-
|
|
|
- var company = response ? (response.hasOwnProperty('company') ? response.company : '') : '';
|
|
|
- this.set_control_company_data(company);
|
|
|
-
|
|
|
- var merchant = response ? (response.hasOwnProperty('merchant') ? response.merchant : '') : '';
|
|
|
- this.set_control_merchant_data(merchant);
|
|
|
-
|
|
|
- }).catch(error => {
|
|
|
- this.mui.toast(error);
|
|
|
- })
|
|
|
- },
|
|
|
- //获取当前用户系统通知数量,未登录用户则置为0
|
|
|
- getSystemMessageNum() {
|
|
|
- API_Common.getSystemMessageNum().then(response => {
|
|
|
-
|
|
|
- this.set_system_message_num(response);
|
|
|
-
|
|
|
- //异步回调父组件的方法
|
|
|
this.asynCallBack();
|
|
|
|
|
|
}).catch(error => {
|
|
|
- //this.mui.toast(error);
|
|
|
- this.set_system_message_num(0)
|
|
|
+ mui.toast(error);
|
|
|
})
|
|
|
},
|
|
|
+
|
|
|
//异步回调父组件的方法
|
|
|
asynCallBack() {
|
|
|
-
|
|
|
- //加载完成后隐藏加载中
|
|
|
- //this.isLoading = false;
|
|
|
-
|
|
|
this.$emit('asynCallBack');
|
|
|
},
|
|
|
...mapMutations({
|
|
|
set_openid: types.SET_WEIXIN_OPENID,
|
|
|
set_token: types.SET_TOKEN,
|
|
|
- set_student_person_data: types.SET_STUDENT_PERSON_DATA,
|
|
|
- set_student_parent_id: types.SET_STUDENT_PARENT_ID,
|
|
|
- set_student_current_info: types.SET_STUDENT_CURRENT_INFO,
|
|
|
- set_teacher_person_data: types.SET_TEACHER_PERSON_DATA,
|
|
|
- set_teacher_company_data: types.SET_TEACHER_COMANY_DATA,
|
|
|
- set_now_role: types.SET_NOW_ROLE,
|
|
|
- set_system_message_num: types.SET_SYSTEM_MESSAGE_NUM,
|
|
|
- set_control_person_data: types.SET_CONTROL_PERSON_DATA,
|
|
|
- set_control_company_data: types.SET_CONTROL_COMPANY_DATA,
|
|
|
- set_control_merchant_data: types.SET_CONTROL_MERCHANT_DATA,
|
|
|
- set_control_type_data: types.SET_CONTROL_TYPE_DATA,
|
|
|
- set_teacher_role: types.SET_TEACHER_ROLE,
|
|
|
- set_now_teacher_role: types.SET_NOW_TEACHER_ROLE,
|
|
|
+ set_person_data: types.SET_PERSON_DATA,
|
|
|
+ set_company_data: types.SET_COMPANY_DATA,
|
|
|
})
|
|
|
},
|
|
|
mounted() {},
|
|
|
computed: {
|
|
|
...mapGetters({
|
|
|
- openId: 'weixin_openid',
|
|
|
+ openId: 'wx_openid',
|
|
|
token: 'token',
|
|
|
- student_person_data: 'student_person_data',
|
|
|
- student_parent_id: 'student_parent_id',
|
|
|
- student_current_info: 'student_current_info',
|
|
|
- now_role: 'now_role',
|
|
|
- teacher_role: 'teacher_role',
|
|
|
- now_teacher_role: 'now_teacher_role',
|
|
|
+ person_data: 'person_data',
|
|
|
+ company_data: 'company_data',
|
|
|
})
|
|
|
}
|
|
|
}
|