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

master
chris 3 months ago
parent 98e2511339
commit f8fe327ee5

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

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

@ -17,6 +17,7 @@
<script setup name="ch-image-uploader">
import { ref, defineProps, reactive, toRefs, watchEffect, watch, computed, defineEmits, defineExpose } from 'vue';
const camera = uni.requireNativePlugin('yun-camerax-module');
const emit = defineEmits(['update:modelValue'])
defineExpose({
upload
@ -72,28 +73,53 @@ function handleSelect (e) {
delImg();
return;
}
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
camera.takePhoto({
// type: 2,
backColor: '',
enableTorch: false,
fullSrc: false
}, (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) {
const newImageList = filterImage(resList)
imageList.value = [...imageList.value, ...newImageList]
} else {
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) {
return imageList.value.map(item => {
return {
name: item.name,
size: item.size,
name: item.name || 'image',
// size: item.size,
uri: item.path,
file: item
// file: item
}
})
}

@ -2,7 +2,7 @@
"name" : "studypen",
"appid" : "__UNI__C183B0D",
"description" : "",
"versionName" : "0.0.0.5",
"versionName" : "0.0.0.8",
"versionCode" : 100,
"transformPx" : false,
/* 5+App */
@ -21,7 +21,8 @@
/* */
"modules" : {
"Camera" : {},
"Bluetooth" : {}
"Bluetooth" : {},
"Statistic" : {}
},
/* */
"distribute" : {
@ -47,7 +48,7 @@
"<uses-permission android:name=\"android.permission.BLUETOOTH_ADMIN\"/>"
],
"minSdkVersion" : 21,
"abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ],
"abiFilters" : [ "armeabi-v7a" ],
"schemes" : "studypen"
},
/* ios */
@ -56,7 +57,15 @@
},
/* SDK */
"sdkConfigs" : {
"ad" : {}
"ad" : {},
"statics" : {
"umeng" : {
"appkey_ios" : "",
"channelid_ios" : "",
"appkey_android" : "666aba86cac2a664de49a838",
"channelid_android" : ""
}
}
},
"splashscreen" : {
"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" : {},

@ -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">
</ch-image-uploader>
</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>
</template>

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

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

@ -10,6 +10,8 @@
</uni-list-item>
<uni-list-item title="家长二维码" show-arrow="true" clickable @click="checkQrcode">
</uni-list-item>
<uni-list-item title="清除数据" show-arrow="true" clickable @click="clearStorage">
</uni-list-item>
</uni-list>
<uni-popup ref="qrcodePopupRef" type="dialog">
<image :src="userInfo.qrcode" mode="aspectFit"></image>
@ -30,10 +32,11 @@ const qrcodePopupRef = ref(null)
const data = reactive({
hadUpdate: false,
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 () {
@ -60,6 +63,20 @@ function checkAppUpdate () {
function checkQrcode () {
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>
<style lang="scss">

@ -12,7 +12,7 @@
:url="uploadUrl">
</ch-image-uploader>
</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>
</template>
@ -20,7 +20,7 @@
import { reactive, toRefs, ref, computed, onMounted } from 'vue';
import ChNavBar from '@/components/ch-nav-bar/ch-nav-bar.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 { uploadTaskImg, getTaskInfo } from '@/api/task.js';
import config from '@/utils/network/config.js'
@ -29,6 +29,7 @@ const userStore = useUserStore();
const userId = userStore.userId;
const imgUploader = ref(null);
const data = reactive({
task: {},
files: [],
@ -38,10 +39,11 @@ const data = reactive({
"width": 400,
},
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)
@ -57,6 +59,7 @@ const uploadUrl = computed(() => {
onLoad((option) => {
taskId.value = option.id;
console.log(uni.canIUse('chooseImage'))
})
onMounted(() => {
@ -71,17 +74,17 @@ onMounted(() => {
console.log(imgArr)
imgArr.forEach(item => {
if (!item) return;
files.value.push({
name: 'studentimg',
extname: 'image/png',
path: `${config.baseUrl}/${item}`
uni.getImageInfo({
src: `${config.baseUrl}/${item}`,
success({ path, type }) {
files.value.push({
name: 'image' + (+new Date()),
extname: `image/${type}`,
path,
})
}
})
})
// files.value = [{
// name: 'studentimg',
// extname: 'image/png',
// path: `${config.baseUrl}/${info.studentimg}`
// }]
})
})

@ -5,7 +5,8 @@ export function setupRouter (app) {
app.use(uniCrazyRouter)
}
const whiteList = ['pages/login/login']
const whiteList = ['pages/login/login'];
// const whiteList = [];
uniCrazyRouter.beforeEach(async (to, from ,next)=>{
console.log('beforEach router')
@ -13,16 +14,23 @@ uniCrazyRouter.beforeEach(async (to, from ,next)=>{
const path = to.url;
const uInfo = uni.getStorageSync('uInfo') || null;
if (whiteList.includes(path) || uInfo) {
next()
if (whiteList.includes(path)) {
next();
return;
}
if (uInfo) {
next();
return;
}
uniCrazyRouter.afterNotNext(() => {
// 拦截路由,并且跳转去登录页
uni.navigateTo({
url: '/pages/login/login'
})
uni.navigateTo({url: '/pages/login/login'})
// if (uInfo) {
// 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) {
return new Promise((resolve, reject) => {
login(params,).then(res => {
login(params).then(res => {
userStore.setUserInfo(res);
uni.setStorageSync('uInfo', JSON.stringify(res));
resolve(res)
}).catch(error => {
console.log('登录失败:', error)

@ -2,13 +2,19 @@ import { defineStore } from 'pinia';
import { ref } from 'vue'
export const useUserStore = defineStore('user', () => {
const userInfo = ref({});
const userInfo = ref(null);
const userId = ref(0);
function setUserInfo(info) {
userInfo.value = info;
uni.setStorageSync('uInfo', JSON.stringify(info));
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',
title: msg
})
reject(msg)
return false
}

Loading…
Cancel
Save