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. 31
      pages/sign/sign.vue
  8. 16
      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 { export default {
async onLaunch() { async onLaunch() {
await this.login();
uni.getSetting({ uni.getSetting({
success(res) { success(res) {
if (!res.authSetting['scope.userLocation']) { if (!res.authSetting['scope.userLocation']) {
@ -14,10 +13,14 @@ export default {
} }
}, },
}); });
await this.login();
this.getSites();
}, },
methods: { methods: {
...mapActions('user', ['login']), ...mapActions('user', ['login']),
...mapActions('site', ['getSites']),
}, },
}; };
</script> </script>

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

@ -2,7 +2,7 @@
<map <map
:latitude="latitude" :latitude="latitude"
:longitude="longitude" :longitude="longitude"
:markers="covers" :markers="markers"
:polygons="polygons" :polygons="polygons"
:polyline="polyline" :polyline="polyline"
id="map" id="map"
@ -14,67 +14,15 @@
<script> <script>
export default { export default {
props: {
markers: { type: Array, default: null },
polyline: { type: Array, default: null },
polygons: { type: Array, default: null },
},
data() { data() {
return { return {
latitude: 37.87059, latitude: 37.87059,
longitude: 112.55067, 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 USER_SIGNS = `${sites}/info`;
// 获取所有场景信息
export const SITES_INFO = `${sites}/siteInfo`;
// 扫码统计 // 扫码统计
export const SCHOOL_SIGNS = `${sites}/statistics`; export const SCHOOL_SIGNS = `${sites}/statistics`;

3
config/config.user.js

@ -5,7 +5,7 @@
*/ */
// 用户登录client // 用户登录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 = { export const SIGN_IN_TYPES = {
@ -16,4 +16,5 @@ export const SIGN_IN_TYPES = {
wx: 4, wx: 4,
wx_web: 5, wx_web: 5,
wb: 6, wb: 6,
wx_work: 7,
}; };

7
pages.json

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

31
pages/sign/sign.vue

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

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

@ -58,10 +58,20 @@ export default {
*/ */
handleChange(value) { handleChange(value) {
const { before, after } = value.range; const { before, after } = value.range;
this.start = before; //
this.end = after; //
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.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="card-content">
<view class="map-wrap"> <view class="map-wrap">
<history-map /> <history-map :markers="markers" />
</view> </view>
</view> </view>
</view> </view>
</template> </template>
<script> <script>
import { mapState } from 'vuex';
export default { export default {
name: 'LocationMap', name: 'LocationMap',
data() {
return {};
},
onLoad() {}, computed: {
...mapState('statistics', ['schoolSigns']),
methods: {}, //
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);
});
return result;
},
},
}; };
</script> </script>

3
store/index.js

@ -1,11 +1,12 @@
import Vue from 'vue'; import Vue from 'vue';
import Vuex from 'vuex'; import Vuex from 'vuex';
import user from './modules/user/index'; import user from './modules/user/index';
import site from './modules/site/index';
import statistics from './modules/statistics/index'; import statistics from './modules/statistics/index';
Vue.use(Vuex); Vue.use(Vuex);
const store = new Vuex.Store({ const store = new Vuex.Store({
modules: { user, statistics }, modules: { user, site, statistics },
}); });
export default store; 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 http
.post(HEALTH_TYPE_STATISTICS, params) .post(HEALTH_TYPE_STATISTICS, params)
.then(res => { .then(res => {
hideLoading();
const { data } = res.data; const { data } = res.data;
commit('setShoolSignNumber', data); commit('setShoolSignNumber', data);
resolve(data); resolve(data);
}) })
.catch(data => { .catch(data => {
hideLoading();
showToast(data.msg || '获取健康上报数据失败'); showToast(data.msg || '获取健康上报数据失败');
reject(data); reject(data);
}); });

2
store/modules/statistics/mutations.js

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

2
store/modules/statistics/state.js

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

2
store/modules/user/actions.js

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

5
utils/user.js

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

Loading…
Cancel
Save