Commit 660378cc98f7fe48e558b7b70e046fed31c72f96
1 parent
b58940ac
快递员端 地图显示bug修复 和登录默认存储用户名密码 ,密码加密处理
Showing
4 changed files
with
74 additions
and
6 deletions
project-wl-kuaidiyuan-uniapp-vue3/package.json
project-wl-kuaidiyuan-uniapp-vue3/pages/login/user.vue
| @@ -51,14 +51,17 @@ import storage from '@/utils/storage.js'; | @@ -51,14 +51,17 @@ import storage from '@/utils/storage.js'; | ||
| 51 | import { userLogins } from '../api/user.js'; | 51 | import { userLogins } from '../api/user.js'; |
| 52 | // 导入接口 | 52 | // 导入接口 |
| 53 | import { getHomeInfo } from '@/pages/api/index.js'; | 53 | import { getHomeInfo } from '@/pages/api/index.js'; |
| 54 | + | ||
| 55 | +import { encrypt, decrypt } from '@/utils/crypto.js' | ||
| 56 | + | ||
| 54 | // ------定义变量------ | 57 | // ------定义变量------ |
| 55 | const store = useStore(); //vuex获取储存数据 | 58 | const store = useStore(); //vuex获取储存数据 |
| 56 | let showPassword = ref(false); //控制密码右侧图标显示隐藏 | 59 | let showPassword = ref(false); //控制密码右侧图标显示隐藏 |
| 57 | const customForm = ref(); //表单校验 | 60 | const customForm = ref(); //表单校验 |
| 58 | // 表单数据 | 61 | // 表单数据 |
| 59 | let fromInfo = reactive({ | 62 | let fromInfo = reactive({ |
| 60 | - account: 'qykdy002', //账号 | ||
| 61 | - password: '123456' // 密码 | 63 | + account: '', //账号 |
| 64 | + password: '' // 密码 | ||
| 62 | }); | 65 | }); |
| 63 | // 表单校验 | 66 | // 表单校验 |
| 64 | const customRules = reactive({ | 67 | const customRules = reactive({ |
| @@ -84,8 +87,17 @@ onMounted(() => { | @@ -84,8 +87,17 @@ onMounted(() => { | ||
| 84 | // 进入登录页面配置默认的请求url | 87 | // 进入登录页面配置默认的请求url |
| 85 | // uni.setStorageSync('baseUrl', 'http://slwl-geteway-t.itheima.net/courier'); | 88 | // uni.setStorageSync('baseUrl', 'http://slwl-geteway-t.itheima.net/courier'); |
| 86 | // 处理定时上报位置的定时器 | 89 | // 处理定时上报位置的定时器 |
| 87 | - clearInterval(uni.getStorageSync('positions').timer); | ||
| 88 | - uni.setStorageSync('positions', null); | 90 | + if(uni.getStorageSync('positions')?.timer) { |
| 91 | + clearInterval(uni.getStorageSync('positions').timer); | ||
| 92 | + uni.setStorageSync('positions', null); | ||
| 93 | + } | ||
| 94 | + const accountHistory = uni.getStorageSync('accountHistory') | ||
| 95 | + if(accountHistory) { | ||
| 96 | + fromInfo.account = accountHistory.account | ||
| 97 | + fromInfo.password = decrypt(accountHistory.password) | ||
| 98 | + // console.log(accountHistory) | ||
| 99 | + } | ||
| 100 | + | ||
| 89 | }); | 101 | }); |
| 90 | // ------定义方法------ | 102 | // ------定义方法------ |
| 91 | // 登录 | 103 | // 登录 |
| @@ -112,6 +124,10 @@ const handleSubmit = async () => { | @@ -112,6 +124,10 @@ const handleSubmit = async () => { | ||
| 112 | // 存储token | 124 | // 存储token |
| 113 | uni.setStorageSync('token', res.data.token); | 125 | uni.setStorageSync('token', res.data.token); |
| 114 | store.commit('user/setToken', res.data.token); | 126 | store.commit('user/setToken', res.data.token); |
| 127 | + | ||
| 128 | + //存储用户账号和密码,密码加密存储 | ||
| 129 | + const data = { account: fromInfo.account, password: encrypt(fromInfo.password) } | ||
| 130 | + uni.setStorageSync('accountHistory', data) | ||
| 115 | // // 通过vuex获取用户信息 | 131 | // // 通过vuex获取用户信息 |
| 116 | store.dispatch('user/GetUsersInfo'); | 132 | store.dispatch('user/GetUsersInfo'); |
| 117 | await getHomeInfo().then(res => { | 133 | await getHomeInfo().then(res => { |
project-wl-kuaidiyuan-uniapp-vue3/pages/my/map.vue
| @@ -9,7 +9,8 @@ | @@ -9,7 +9,8 @@ | ||
| 9 | :latitude="latitude" | 9 | :latitude="latitude" |
| 10 | :longitude="longitude" | 10 | :longitude="longitude" |
| 11 | :polygons="polygons" | 11 | :polygons="polygons" |
| 12 | - scale="16" | 12 | + :enable-zoom="true" |
| 13 | + scale="10" | ||
| 13 | ></map | 14 | ></map |
| 14 | ></view> | 15 | ></view> |
| 15 | </template> | 16 | </template> |
| @@ -66,14 +67,49 @@ onMounted(() => { | @@ -66,14 +67,49 @@ onMounted(() => { | ||
| 66 | getUserPolygon(); | 67 | getUserPolygon(); |
| 67 | }); | 68 | }); |
| 68 | // ------定义方法------ | 69 | // ------定义方法------ |
| 70 | + | ||
| 71 | +const getGeoCenter = (points) => { | ||
| 72 | + let x = 0, y = 0, z = 0 | ||
| 73 | + | ||
| 74 | + points.forEach(p => { | ||
| 75 | + const lat = p.latitude * Math.PI / 180 | ||
| 76 | + const lng = p.longitude * Math.PI / 180 | ||
| 77 | + | ||
| 78 | + x += Math.cos(lat) * Math.cos(lng) | ||
| 79 | + y += Math.cos(lat) * Math.sin(lng) | ||
| 80 | + z += Math.sin(lat) | ||
| 81 | + }) | ||
| 82 | + | ||
| 83 | + const total = points.length | ||
| 84 | + x /= total; y /= total; z /= total | ||
| 85 | + | ||
| 86 | + const lng = Math.atan2(y, x) | ||
| 87 | + const hyp = Math.sqrt(x * x + y * y) | ||
| 88 | + const lat = Math.atan2(z, hyp) | ||
| 89 | + | ||
| 90 | + return { | ||
| 91 | + longitude: lng * 180 / Math.PI, | ||
| 92 | + latitude: lat * 180 / Math.PI | ||
| 93 | + } | ||
| 94 | +} | ||
| 95 | + | ||
| 96 | + | ||
| 69 | // 获取作业范围 | 97 | // 获取作业范围 |
| 70 | const getUserPolygon = async () => { | 98 | const getUserPolygon = async () => { |
| 71 | await getUserScope().then((res) => { | 99 | await getUserScope().then((res) => { |
| 72 | if (res.code === 200) { | 100 | if (res.code === 200) { |
| 73 | - // TODO暂时保留 | 101 | + // TODO暂时保留 |
| 74 | // polygons[0].points=res.data.polygon | 102 | // polygons[0].points=res.data.polygon |
| 75 | // latitude.value=polygons[0].points[0].latitude | 103 | // latitude.value=polygons[0].points[0].latitude |
| 76 | // longitude.value=polygons[0].points[0].longitude | 104 | // longitude.value=polygons[0].points[0].longitude |
| 105 | + | ||
| 106 | + if(res.data.polygon) { | ||
| 107 | + const {longitude : lng, latitude: lat} = getGeoCenter(res.data.polygon) | ||
| 108 | + latitude.value = lat | ||
| 109 | + longitude.value = lng | ||
| 110 | + polygons[0].points=res.data.polygon | ||
| 111 | + | ||
| 112 | + } | ||
| 77 | } | 113 | } |
| 78 | }); | 114 | }); |
| 79 | }; | 115 | }; |
project-wl-kuaidiyuan-uniapp-vue3/utils/crypto.js
0 → 100644
| 1 | +import CryptoJS from 'crypto-js' | ||
| 2 | + | ||
| 3 | +// 一个固定密钥(自己换掉) | ||
| 4 | +const SECRET_KEY = 'dili-tms' | ||
| 5 | + | ||
| 6 | +// AES 加密 | ||
| 7 | +export function encrypt(data) { | ||
| 8 | + return CryptoJS.AES.encrypt(data, SECRET_KEY).toString() | ||
| 9 | +} | ||
| 10 | + | ||
| 11 | +// AES 解密 | ||
| 12 | +export function decrypt(cipherText) { | ||
| 13 | + const bytes = CryptoJS.AES.decrypt(cipherText, SECRET_KEY) | ||
| 14 | + return bytes.toString(CryptoJS.enc.Utf8) | ||
| 15 | +} |