Browse Source

1.打卡

2.统计
remotes/origin/HEAD
wally 5 years ago
parent
commit
ecaace8ef6
  1. 5
      App.vue
  2. 64
      components/history-map/history-map.vue
  3. 101
      components/school-map/school-map.vue
  4. 3
      config/api/api.js
  5. 3
      config/config.user.js
  6. 7
      pages.json
  7. 29
      pages/sign/sign.vue
  8. 12
      pages/statistics/components/date-selector.vue
  9. 37
      pages/statistics/components/location-map.vue
  10. 3
      store/index.js
  11. 53
      store/modules/site/actions.js
  12. 5
      store/modules/site/index.js
  13. 12
      store/modules/site/mutations.js
  14. 5
      store/modules/site/state.js
  15. 2
      store/modules/statistics/actions.js
  16. 2
      store/modules/statistics/mutations.js
  17. 2
      store/modules/statistics/state.js
  18. 2
      store/modules/user/actions.js
  19. 5
      utils/user.js

5
App.vue

@ -3,7 +3,6 @@ import { mapActions } from 'vuex';
export default {
async onLaunch() {
await this.login();
uni.getSetting({
success(res) {
if (!res.authSetting['scope.userLocation']) {
@ -14,10 +13,14 @@ export default {
}
},
});
await this.login();
this.getSites();
},
methods: {
...mapActions('user', ['login']),
...mapActions('site', ['getSites']),
},
};
</script>

64
components/history-map/history-map.vue

@ -2,7 +2,7 @@
<map
:latitude="latitude"
:longitude="longitude"
:markers="covers"
:markers="markers"
:polygons="polygons"
:polyline="polyline"
id="map"
@ -14,67 +14,15 @@
<script>
export default {
props: {
markers: { type: Array, default: null },
polyline: { type: Array, default: null },
polygons: { type: Array, default: null },
},
data() {
return {
latitude: 37.87059,
longitude: 112.55067,
covers: [
{
latitude: 37.87059,
longitude: 112.55067,
iconPath: '../../static/location.png',
callout: {
content: 'test',
color: '#fff',
padding: 4,
bgColor: '#0A97C6',
borderRadius: 2,
textAlign: 'center',
},
},
{
latitude: 37.87,
longitude: 112.5506,
iconPath: '../../static/location.png',
},
{
latitude: 37.8701,
longitude: 112.55,
iconPath: '../../static/location.png',
},
{
latitude: 37.86,
longitude: 112.5496,
iconPath: '../../static/location.png',
},
],
polyline: [
{
points: [
{ latitude: 37.87059, longitude: 112.55067 },
{ latitude: 37.87, longitude: 112.5506 },
{ latitude: 37.8701, longitude: 112.55 },
{ latitude: 37.86, longitude: 112.5496 },
],
arrowLine: true,
dottedLine: true,
borderColor: '#cccccc',
},
],
polygons: [
{
points: [
{ latitude: 37.87059, longitude: 112.55067 },
{ latitude: 37.87, longitude: 112.5506 },
{ latitude: 37.8701, longitude: 112.55 },
{ latitude: 37.86, longitude: 112.5496 },
],
strokeWidth: 0,
strokeColor: '#00000000',
fillColor: '#cce6ff88',
zIndex: 0,
},
],
};
},

101
components/school-map/school-map.vue

@ -0,0 +1,101 @@
<template>
<map
:latitude="latitude"
:longitude="longitude"
:markers="covers"
:polygons="polygons"
:polyline="polyline"
id="map"
ref="map"
show-location="true"
style="width: 100%; height: 1000rpx;"
/>
</template>
<script>
export default {
data() {
return {
latitude: 37.87059,
longitude: 112.55067,
covers: [
{
latitude: 37.87059,
longitude: 112.55067,
iconPath: '../../static/location.png',
callout: {
content: 'test',
color: '#fff',
padding: 4,
bgColor: '#0A97C6',
borderRadius: 2,
textAlign: 'center',
},
},
{
latitude: 37.87,
longitude: 112.5506,
iconPath: '../../static/location.png',
},
{
latitude: 37.8701,
longitude: 112.55,
iconPath: '../../static/location.png',
},
{
latitude: 37.86,
longitude: 112.5496,
iconPath: '../../static/location.png',
},
],
polyline: [
{
points: [
{ latitude: 37.87059, longitude: 112.55067 },
{ latitude: 37.87, longitude: 112.5506 },
{ latitude: 37.8701, longitude: 112.55 },
{ latitude: 37.86, longitude: 112.5496 },
],
arrowLine: true,
dottedLine: true,
borderColor: '#cccccc',
},
],
polygons: [
{
points: [
{ latitude: 37.87059, longitude: 112.55067 },
{ latitude: 37.87, longitude: 112.5506 },
{ latitude: 37.8701, longitude: 112.55 },
{ latitude: 37.86, longitude: 112.5496 },
],
strokeWidth: 0,
strokeColor: '#00000000',
fillColor: '#cce6ff88',
zIndex: 0,
},
],
};
},
onLoad() {
this.getLocation();
},
methods: {
//
// mapgcj02
getLocation() {
uni.getLocation({
type: 'gcj02',
success: res => {
this.longitude = res.longitude;
this.latitude = res.latitude;
console.log('当前位置的经度:' + res.longitude);
console.log('当前位置的纬度:' + res.latitude);
},
});
},
},
};
</script>

3
config/api/api.js

@ -25,6 +25,9 @@ export const HEALTH_SIGN = `${health}/upload`;
// 查看自己的打卡记录
export const USER_SIGNS = `${sites}/info`;
// 获取所有场景信息
export const SITES_INFO = `${sites}/siteInfo`;
// 扫码统计
export const SCHOOL_SIGNS = `${sites}/statistics`;

3
config/config.user.js

@ -5,7 +5,7 @@
*/
// 用户登录client
export const SIGN_IN_CLIENTS = { mp: 0, h5: 1, android: 2, ios: 3 };
export const SIGN_IN_CLIENTS = { mp: 0, h5: 1, android: 2, ios: 3, wx_work: 4 };
// 用户登录类型
export const SIGN_IN_TYPES = {
@ -16,4 +16,5 @@ export const SIGN_IN_TYPES = {
wx: 4,
wx_web: 5,
wb: 6,
wx_work: 7,
};

7
pages.json

@ -1,12 +1,5 @@
{
"pages": [
// {
// "path": "pages/my-code/my-code",
// "style": {
// "navigationBarTitleText": "我的健康打卡"
// }
// },
{
"path": "pages/index/index",
"style": {

29
pages/sign/sign.vue

@ -4,7 +4,7 @@
<view class="text-xxl padding text-center margin-top-xl">
<text class="text-black text-bold">{{ address }}</text>
</view>
<button @tap="handleSign" class="cu-btn lg bg-purple margin sign-btn">打卡</button>
<button @tap="handleSign(siteId)" class="cu-btn lg bg-purple margin sign-btn">{{ typeText }}</button>
</template>
<view class="success" v-else>
<view class="cuIcon-roundcheckfill text-green"></view>
@ -15,6 +15,7 @@
</template>
<script>
import { mapActions } from 'vuex';
import { formatQuery } from 'utils/util';
import { SCAN_SIGN } from 'api/api';
@ -26,22 +27,30 @@ export default {
siteId: '',
siteName: '',
success: false,
type: 0, // 0 / 1
};
},
computed: {
typeText() {
return this.type === 0 ? '进场打卡' : '出场打卡';
},
},
onLoad(options) {
try {
console.log('options: ', options);
const query = formatQuery(decodeURIComponent(options.scene));
const { siteId, siteName } = query;
this.siteId = query.siteId;
this.siteName = query.siteName;
console.log('query: ', query);
const { d, t } = query;
this.siteId = d;
this.type = +t;
} catch (error) {
console.log('error: ', error);
}
},
methods: {
...mapActions('site', ['sign']),
/**
* 扫码打卡
* @param {string} siteId 场所id
@ -50,18 +59,10 @@ export default {
try {
console.log('打卡');
const params = { param: { siteId } };
const res = await this.$http.post(SCAN_SIGN, params);
const { success, code, msg, data } = res.data;
if (success && code === 200) {
await this.sign(params);
this.success = true;
} else {
uni.showToast({ title: msg || '打卡失败', icon: 'none' });
}
} catch (error) {
console.log('error: ', error);
if (error.msg) {
uni.showToast({ title: error.msg || '打卡失败', icon: 'none' });
}
}
},
},

12
pages/statistics/components/date-selector.vue

@ -58,10 +58,20 @@ export default {
*/
handleChange(value) {
const { before, after } = value.range;
//
//
if (before && !after) {
this.start = before;
this.end = before;
} else if (!before && after) {
this.end = after;
this.start = after;
} else if (before && after) {
this.start = before;
this.end = after;
}
this.menu = '';
this.$emit('change', before, after);
this.$emit('change', this.start, this.end);
},
/**

37
pages/statistics/components/location-map.vue

@ -11,21 +11,46 @@
<view class="card-content">
<view class="map-wrap">
<history-map />
<history-map :markers="markers" />
</view>
</view>
</view>
</template>
<script>
import { mapState } from 'vuex';
export default {
name: 'LocationMap',
data() {
return {};
},
onLoad() {},
computed: {
...mapState('statistics', ['schoolSigns']),
//
markers() {
if (!this.schoolSigns) return null;
const result = [];
this.schoolSigns.forEach(item => {
const content = `${item.siteName}\n${item.number}`;
const obj = {
latitude: item.latitude,
longitude: item.longitude,
iconPath: '/static/location.png',
callout: {
content,
display: 'ALWAYS',
color: '#fff',
padding: 4,
bgColor: '#0A97C6',
borderRadius: 2,
textAlign: 'center',
},
};
result.push(obj);
});
methods: {},
return result;
},
},
};
</script>

3
store/index.js

@ -1,11 +1,12 @@
import Vue from 'vue';
import Vuex from 'vuex';
import user from './modules/user/index';
import site from './modules/site/index';
import statistics from './modules/statistics/index';
Vue.use(Vuex);
const store = new Vuex.Store({
modules: { user, statistics },
modules: { user, site, statistics },
});
export default store;

53
store/modules/site/actions.js

@ -0,0 +1,53 @@
import { http } from 'plugins/request/index';
import { showLoading, hideLoading, showToast, showModal } from 'utils/ui';
import { SITES_INFO, SCAN_SIGN } from 'api/api';
const actions = {
/**
* 获取所有场所信息
* @param {*} commit
*/
getSites({ commit }) {
return new Promise((resolve, reject) => {
showLoading();
http
.post(SITES_INFO)
.then(res => {
hideLoading();
const { data } = res.data;
commit('setSites', data);
resolve(data);
})
.catch(data => {
hideLoading();
showToast(data.msg || '获取场所信息失败');
reject(data);
});
});
},
/**
* 扫码打卡 提交打卡记录
* @param {*} commit
* @param {object} params 提交服务端的数据
*/
sign({ commit }, params) {
return new Promise((resolve, reject) => {
showLoading();
http
.post(SCAN_SIGN, params)
.then(res => {
hideLoading();
const { data } = res.data;
resolve(data);
})
.catch(data => {
hideLoading();
showToast(data.msg || '打卡失败');
reject(data);
});
});
},
};
export default actions;

5
store/modules/site/index.js

@ -0,0 +1,5 @@
import state from './state';
import mutations from './mutations';
import actions from './actions.js';
export default { namespaced: true, state, actions, mutations };

12
store/modules/site/mutations.js

@ -0,0 +1,12 @@
const mutations = {
/**
* 设置所有的场所值
* @param {object} state
* @param {array} data
*/
setSites(state, data) {
state.sites = data || [];
},
};
export default mutations;

5
store/modules/site/state.js

@ -0,0 +1,5 @@
const state = {
sites: [], // 所有的场所信息
};
export default state;

2
store/modules/statistics/actions.js

@ -64,11 +64,13 @@ const actions = {
http
.post(HEALTH_TYPE_STATISTICS, params)
.then(res => {
hideLoading();
const { data } = res.data;
commit('setShoolSignNumber', data);
resolve(data);
})
.catch(data => {
hideLoading();
showToast(data.msg || '获取健康上报数据失败');
reject(data);
});

2
store/modules/statistics/mutations.js

@ -14,7 +14,7 @@ const mutations = {
* @param {array} data
*/
setSchoolSigns(state, data) {
state.shoolSigns = data || [];
state.schoolSigns = data || [];
},
/**

2
store/modules/statistics/state.js

@ -1,6 +1,6 @@
const state = {
userSigns: [], // 用户个人打卡记录
shoolSigns: [], // 校园的打卡记录
schoolSigns: [], // 校园的打卡记录
shoolSignNumber: [
{ name: '正常', number: '-' },
{ name: '发烧', number: '-' },

2
store/modules/user/actions.js

@ -10,11 +10,13 @@ const actions = {
mpLogin()
.then(params => signIn(params))
.then(data => {
console.log('login data: ', data);
commit('setToken', data.token);
commit('setUser', data);
resolve(data);
})
.catch(err => {
console.log('login err: ', err);
// showModal(err.msg || '登录失败');
reject(err);
});

5
utils/user.js

@ -77,8 +77,8 @@ export const wxWorkLogin = () => {
success(response) {
if (response.code) {
const params = {
client: SIGN_IN_CLIENTS['mp'],
type: SIGN_IN_TYPES['mp'],
client: SIGN_IN_CLIENTS['wx_work'],
type: SIGN_IN_TYPES['wx_work'],
data: { identifier: response.code, credential: 'health' },
redirect: 'https://test.tall.wiki/gateway/health/initMsg',
};
@ -99,6 +99,7 @@ export const wxWorkLogin = () => {
export const mpLogin = () => {
try {
const res = uni.getSystemInfoSync();
console.log('res.environment: ', res.environment);
if (res.environment === 'wxwork') {
return wxWorkLogin();
} else {

Loading…
Cancel
Save