1、增加用户数据缓存,解决重复登录问题; 2、增加原生相机,解决uni api调用相机闪退问题;3、设置页面增加清除用户数据并退回登录页功能;

master
chris 3 months ago
parent 98e2511339
commit f8fe327ee5

@ -3,7 +3,7 @@
"configurations" : [ "configurations" : [
{ {
"openVueDevtools" : true, "openVueDevtools" : true,
"playground" : "standard", "playground" : "custom",
"type" : "uni-app:app-android" "type" : "uni-app:app-android"
}, },
{ {

@ -27,9 +27,10 @@
}) })
onBeforeMount(() => { onBeforeMount(() => {
const userInfo = uni.getStorageSync('uInfo') // const userInfo = uni.getStorageSync('uInfo')
const userInfo = userStore.getUserInfo();
if (userInfo) { if (userInfo) {
userStore.setUserInfo(JSON.parse(userInfo)) userStore.setUserInfo(userInfo)
} }
}) })
</script> </script>

@ -17,6 +17,7 @@
<script setup name="ch-image-uploader"> <script setup name="ch-image-uploader">
import { ref, defineProps, reactive, toRefs, watchEffect, watch, computed, defineEmits, defineExpose } from 'vue'; import { ref, defineProps, reactive, toRefs, watchEffect, watch, computed, defineEmits, defineExpose } from 'vue';
const camera = uni.requireNativePlugin('yun-camerax-module');
const emit = defineEmits(['update:modelValue']) const emit = defineEmits(['update:modelValue'])
defineExpose({ defineExpose({
upload upload
@ -72,28 +73,53 @@ function handleSelect (e) {
delImg(); delImg();
return; return;
} }
camera.takePhoto({
uni.chooseImage({ // type: 2,
count: props.limit, backColor: '',
extension: props.extList, enableTorch: false,
sourceType: props.sourceType, fullSrc: false
success: (res) => { }, (res) => {
console.log(res) uni.getImageInfo({
src: res.file,
success: (info) => {
console.log(info)
const resList = [{
name: 'image' + (+new Date()),
extname: `image/${info.type}`,
path: info.path,
}];
if (props.limit > 1) { if (props.limit > 1) {
const newImageList = filterImage(res.tempFiles) const newImageList = filterImage(resList)
imageList.value = [...imageList.value, ...newImageList] imageList.value = [...imageList.value, ...newImageList]
} else { } else {
imageList.value = res.tempFiles imageList.value = resList
} }
emit('update:modelValue', imageList.value) emit('update:modelValue', imageList.value)
},
fail: (res) => {
uni.showToast({
icon: 'error',
title: '选择失败'
})
} }
}) })
})
// uni.chooseImage({
// count: props.limit,
// extension: props.extList,
// sourceType: props.sourceType,
// success: (res) => {
// console.log(res)
// if (props.limit > 1) {
// const newImageList = filterImage(res.tempFiles)
// imageList.value = [...imageList.value, ...newImageList]
// } else {
// imageList.value = res.tempFiles
// }
// emit('update:modelValue', imageList.value)
// },
// fail: (res) => {
// uni.showToast({
// icon: 'error',
// title: ''
// })
// }
// })
} }
// //
@ -132,10 +158,10 @@ function delImg (path) {
function formatImageFiles (fileList) { function formatImageFiles (fileList) {
return imageList.value.map(item => { return imageList.value.map(item => {
return { return {
name: item.name, name: item.name || 'image',
size: item.size, // size: item.size,
uri: item.path, uri: item.path,
file: item // file: item
} }
}) })
} }

@ -2,7 +2,7 @@
"name" : "studypen", "name" : "studypen",
"appid" : "__UNI__C183B0D", "appid" : "__UNI__C183B0D",
"description" : "", "description" : "",
"versionName" : "0.0.0.5", "versionName" : "0.0.0.8",
"versionCode" : 100, "versionCode" : 100,
"transformPx" : false, "transformPx" : false,
/* 5+App */ /* 5+App */
@ -21,7 +21,8 @@
/* */ /* */
"modules" : { "modules" : {
"Camera" : {}, "Camera" : {},
"Bluetooth" : {} "Bluetooth" : {},
"Statistic" : {}
}, },
/* */ /* */
"distribute" : { "distribute" : {
@ -47,7 +48,7 @@
"<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>" "<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>"
], ],
"minSdkVersion" : 21, "minSdkVersion" : 21,
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ], "abiFilters" : [ "armeabi-v7a" ],
"schemes" : "studypen" "schemes" : "studypen"
}, },
/* ios */ /* ios */
@ -56,7 +57,15 @@
}, },
/* SDK */ /* SDK */
"sdkConfigs" : { "sdkConfigs" : {
"ad" : {} "ad" : {},
"statics" : {
"umeng" : {
"appkey_ios" : "",
"channelid_ios" : "",
"appkey_android" : "666aba86cac2a664de49a838",
"channelid_android" : ""
}
}
}, },
"splashscreen" : { "splashscreen" : {
"androidStyle" : "default", "androidStyle" : "default",
@ -75,7 +84,22 @@
} }
} }
}, },
"nativePlugins" : {} "nativePlugins" : {
"yun-camerax" : {
"__plugin_info__" : {
"name" : "身份证相机",
"description" : "自定义身份证相机",
"platforms" : "Android",
"url" : "",
"android_package_name" : "",
"ios_bundle_id" : "",
"isCloud" : false,
"bought" : -1,
"pid" : "",
"parameters" : {}
}
}
}
}, },
/* */ /* */
"quickapp" : {}, "quickapp" : {},

@ -0,0 +1,17 @@
{
"name": "相机测试",
"id": "DeltaPhone-Camera",
"version": "1.4",
"description": "相机测试",
"_dp_type": "nativeplugin",
"_dp_nativeplugin": {
"android": {
"plugins": [{
"type": "module",
"name": "DeltaPhone-Camera",
"class": "com.deltaphone.cameramodule.CameraModule"
}],
"integrateType": "aar"
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

@ -0,0 +1,26 @@
{
"name": "身份证相机",
"id": "yun-camerax",
"version": "1.3.0",
"description": "自定义身份证相机",
"_dp_type": "nativeplugin",
"_dp_nativeplugin": {
"android": {
"plugins": [{
"type": "module",
"name": "yun-camerax-module",
"class": "com.yun.camera.CameraModule"
}],
"integrateType": "aar",
"minSdkVersion": "26",
"useAndroidX": true,
"dependencies": [
"androidx.constraintlayout:constraintlayout:2.0.4",
"androidx.camera:camera-core:1.1.0-alpha01",
"androidx.camera:camera-camera2:1.1.0-alpha01",
"androidx.camera:camera-lifecycle:1.1.0-alpha01",
"androidx.camera:camera-view:1.0.0-alpha27"
]
}
}
}

@ -27,7 +27,7 @@
:url="uploadUrl"> :url="uploadUrl">
</ch-image-uploader> </ch-image-uploader>
</uni-list> </uni-list>
<button class="submit-btn" type="primary" :disabled="isDisable" @click="submitExam"></button> <button class="submit-btn" type="primary" :loading="uploading" :disabled="isDisable" @click="submitExam"></button>
</view> </view>
</template> </template>

@ -85,7 +85,7 @@ const data = reactive({
const { gridList, userInfo } = toRefs(data); const { gridList, userInfo } = toRefs(data);
onLoad(() => { onLoad(() => {
userInfo.value = userStore.userInfo; userInfo.value = userStore.getUserInfo();
}) })
function clickMenuItem(url) { function clickMenuItem(url) {

@ -26,6 +26,8 @@ import { ref, reactive, toRefs } from 'vue';
import useForm from '@/useModules/useForm.js'; import useForm from '@/useModules/useForm.js';
import ChFlex from '@/components/ch-flex/ch-flex.vue'; import ChFlex from '@/components/ch-flex/ch-flex.vue';
import { useSystemStore } from '@/store/system.js'; import { useSystemStore } from '@/store/system.js';
import { useUserStore } from '@/store/user.js';
import { onLoad, onInit } from '@dcloudio/uni-app';
const defaultForm = { const defaultForm = {
studentno: '', studentno: '',
@ -34,6 +36,7 @@ const defaultForm = {
} }
const systemStore = useSystemStore(); const systemStore = useSystemStore();
const userStore = useUserStore();
const formRef = ref(); const formRef = ref();
@ -66,19 +69,30 @@ const data = reactive({
const { rules, schoolList, loading } = toRefs(data); const { rules, schoolList, loading } = toRefs(data);
onLoad(() => {
const info = userStore.getUserInfo()
console.log(info);
if (info) {
uni.redirectTo({
url: '/pages/index/index'
})
}
})
function login () { function login () {
validateForm().then(status => { validateForm().then(status => {
if(!status) return false; if(!status) return false;
loading.value = true; loading.value = true;
systemStore.Login(form).then(res => { systemStore.Login(form).then(res => {
uni.navigateTo({ uni.redirectTo({
url: '/pages/index/index' url: '/pages/index/index'
}) })
}).catch(error => { }).catch(error => {
uni.showToast({ // loading.value = false;
icon: 'fail', // uni.showToast({
title: '登录失败' // icon: 'error',
}) // title: ''
// })
}).finally(() => { }).finally(() => {
loading.value = false; loading.value = false;
}) })

@ -10,6 +10,8 @@
</uni-list-item> </uni-list-item>
<uni-list-item title="家长二维码" show-arrow="true" clickable @click="checkQrcode"> <uni-list-item title="家长二维码" show-arrow="true" clickable @click="checkQrcode">
</uni-list-item> </uni-list-item>
<uni-list-item title="清除数据" show-arrow="true" clickable @click="clearStorage">
</uni-list-item>
</uni-list> </uni-list>
<uni-popup ref="qrcodePopupRef" type="dialog"> <uni-popup ref="qrcodePopupRef" type="dialog">
<image :src="userInfo.qrcode" mode="aspectFit"></image> <image :src="userInfo.qrcode" mode="aspectFit"></image>
@ -30,10 +32,11 @@ const qrcodePopupRef = ref(null)
const data = reactive({ const data = reactive({
hadUpdate: false, hadUpdate: false,
appInfo: sysStore.appInfo, appInfo: sysStore.appInfo,
userInfo: userStore.userInfo userInfo: userStore.userInfo,
count: 0
}) })
const { hadUpdate, appInfo, userInfo } = toRefs(data); const { hadUpdate, appInfo, userInfo, count } = toRefs(data);
// //
function checkAppUpdate () { function checkAppUpdate () {
@ -60,6 +63,20 @@ function checkAppUpdate () {
function checkQrcode () { function checkQrcode () {
qrcodePopupRef.value.open('center') qrcodePopupRef.value.open('center')
} }
function clearStorage () {
count.value++;
if (count.value < 3) return;
uni.clearStorageSync();
uni.showToast({
title: '清除成功',
success() {
uni.reLaunch({
url: '/pages/login/login'
})
}
})
}
</script> </script>
<style lang="scss"> <style lang="scss">

@ -12,7 +12,7 @@
:url="uploadUrl"> :url="uploadUrl">
</ch-image-uploader> </ch-image-uploader>
</uni-list> </uni-list>
<button class="submit-btn" type="primary" :disabled="isDisable" @click="submitTask"></button> <button class="submit-btn" type="primary" :loading="uploading" :disabled="isDisable" @click="submitTask"></button>
</view> </view>
</template> </template>
@ -20,7 +20,7 @@
import { reactive, toRefs, ref, computed, onMounted } from 'vue'; import { reactive, toRefs, ref, computed, onMounted } from 'vue';
import ChNavBar from '@/components/ch-nav-bar/ch-nav-bar.vue'; import ChNavBar from '@/components/ch-nav-bar/ch-nav-bar.vue';
import ChImageUploader from '@/components/ch-image-uploader/ch-image-uploader.vue'; import ChImageUploader from '@/components/ch-image-uploader/ch-image-uploader.vue';
import { onLoad } from '@dcloudio/uni-app' import { onLoad, onUnload } from '@dcloudio/uni-app'
import { useUserStore } from '@/store/user.js' import { useUserStore } from '@/store/user.js'
import { uploadTaskImg, getTaskInfo } from '@/api/task.js'; import { uploadTaskImg, getTaskInfo } from '@/api/task.js';
import config from '@/utils/network/config.js' import config from '@/utils/network/config.js'
@ -29,6 +29,7 @@ const userStore = useUserStore();
const userId = userStore.userId; const userId = userStore.userId;
const imgUploader = ref(null); const imgUploader = ref(null);
const data = reactive({ const data = reactive({
task: {}, task: {},
files: [], files: [],
@ -38,10 +39,11 @@ const data = reactive({
"width": 400, "width": 400,
}, },
taskId: '', taskId: '',
uploading: false uploading: false,
igUrl: ''
}) })
const { task, img, imgStyle , files, taskId, uploading } = toRefs(data); const { task, img, imgStyle , files, taskId, uploading, igUrl } = toRefs(data);
const isDisable = computed(() => !files.value.length || uploading.value) const isDisable = computed(() => !files.value.length || uploading.value)
@ -57,6 +59,7 @@ const uploadUrl = computed(() => {
onLoad((option) => { onLoad((option) => {
taskId.value = option.id; taskId.value = option.id;
console.log(uni.canIUse('chooseImage'))
}) })
onMounted(() => { onMounted(() => {
@ -71,17 +74,17 @@ onMounted(() => {
console.log(imgArr) console.log(imgArr)
imgArr.forEach(item => { imgArr.forEach(item => {
if (!item) return; if (!item) return;
uni.getImageInfo({
src: `${config.baseUrl}/${item}`,
success({ path, type }) {
files.value.push({ files.value.push({
name: 'studentimg', name: 'image' + (+new Date()),
extname: 'image/png', extname: `image/${type}`,
path: `${config.baseUrl}/${item}` path,
})
}
}) })
}) })
// files.value = [{
// name: 'studentimg',
// extname: 'image/png',
// path: `${config.baseUrl}/${info.studentimg}`
// }]
}) })
}) })

@ -5,7 +5,8 @@ export function setupRouter (app) {
app.use(uniCrazyRouter) app.use(uniCrazyRouter)
} }
const whiteList = ['pages/login/login'] const whiteList = ['pages/login/login'];
// const whiteList = [];
uniCrazyRouter.beforeEach(async (to, from ,next)=>{ uniCrazyRouter.beforeEach(async (to, from ,next)=>{
console.log('beforEach router') console.log('beforEach router')
@ -13,16 +14,23 @@ uniCrazyRouter.beforeEach(async (to, from ,next)=>{
const path = to.url; const path = to.url;
const uInfo = uni.getStorageSync('uInfo') || null; const uInfo = uni.getStorageSync('uInfo') || null;
if (whiteList.includes(path) || uInfo) { if (whiteList.includes(path)) {
next() next();
return;
}
if (uInfo) {
next();
return; return;
} }
uniCrazyRouter.afterNotNext(() => { uniCrazyRouter.afterNotNext(() => {
// 拦截路由,并且跳转去登录页 uni.navigateTo({url: '/pages/login/login'})
uni.navigateTo({ // if (uInfo) {
url: '/pages/login/login' // uni.navigateTo({url: '/pages/index/index'})
}) // } else {
// uni.navigateTo({url: '/pages/login/login'})
// }
}) })
}) })

@ -13,9 +13,8 @@ export const useSystemStore = defineStore('system', () => {
function Login(params) { function Login(params) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
login(params,).then(res => { login(params).then(res => {
userStore.setUserInfo(res); userStore.setUserInfo(res);
uni.setStorageSync('uInfo', JSON.stringify(res));
resolve(res) resolve(res)
}).catch(error => { }).catch(error => {
console.log('登录失败:', error) console.log('登录失败:', error)

@ -2,13 +2,19 @@ import { defineStore } from 'pinia';
import { ref } from 'vue' import { ref } from 'vue'
export const useUserStore = defineStore('user', () => { export const useUserStore = defineStore('user', () => {
const userInfo = ref({}); const userInfo = ref(null);
const userId = ref(0); const userId = ref(0);
function setUserInfo(info) { function setUserInfo(info) {
userInfo.value = info; userInfo.value = info;
uni.setStorageSync('uInfo', JSON.stringify(info));
userId.value = info.studentid userId.value = info.studentid
} }
return { userInfo, userId, setUserInfo }; function getUserInfo() {
const info = uni.getStorageSync('uInfo');
return userInfo.value || (info ? JSON.parse(info) : null);
}
return { userInfo, userId, setUserInfo, getUserInfo };
}) })

@ -65,6 +65,7 @@ function request ({ url, method, data = {} }, config = { loading: true }) {
icon: 'error', icon: 'error',
title: msg title: msg
}) })
reject(msg)
return false return false
} }

Loading…
Cancel
Save