等待安卓对接

This commit is contained in:
李彪 2025-04-10 09:12:18 +08:00
parent 8efffa4b94
commit f9e3cb3f93
10 changed files with 452 additions and 62 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.history
unpackage/dist

144
App.vue
View File

@ -1,63 +1,95 @@
<script>
// #ifdef APP-PLUS
import appUpdate from "@/components/appUpdate/appUpdate.js";
// #endif
// #ifdef APP-PLUS
import appUpdate from '@/components/appUpdate/appUpdate.js'
// #endif
export default {
onLaunch: function () {
console.log("%c%s", "color:red", "onLaunch---");
uni.showLoading({ title: "等待参数传入" });
// uni.setStorageSync("token", "");
window.initFn = this.initFn;
// this.initFn();
//console.log('App Launch')
// #ifdef APP-PLUS
let systemInfo = uni.getSystemInfoSync();
const data = {
appid: systemInfo.appId,
version: systemInfo.appVersion,
};
console.log(data);
//appid
this.$api.checkVersion(data).then((res) => {
console.log(res);
if (res.code == 0) {
//0
appUpdate(res);
}
});
// #endif
},
onShow: function () {
// console.log('%c%s', 'color:red', 'onShow---');
// #ifdef MP-WEIXIN
export default {
onLaunch: function() {
//console.log('App Launch')
// #ifdef APP-PLUS
let systemInfo = uni.getSystemInfoSync()
const data={
appid: systemInfo.appId,
version: systemInfo.appVersion
}
console.log(data)
//appid
this.$api.checkVersion(data).then(res => {
console.log(res)
if(res.code==0){
//0
appUpdate(res)
}
})
// #endif
},
onShow: function() {
// #ifdef MP-WEIXIN
// res: {hasUpdate: true, version: 1.0.0}
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) {
//
uni.showLoading({ title: "更新中..." }); // Loading
}
});
//
updateManager.onUpdateReady(function () {
uni.hideLoading(); // Loading
uni.showModal({
//
title: "更新提示",
content: "更新完毕,是否重启?",
success: function (res) {
if (res.confirm) {
updateManager.applyUpdate(); // 使
}
},
});
});
//
updateManager.onUpdateFailed(function () {
uni.hideLoading(); // Loading
uni.showToast({ title: "更新失败,稍后再试...", icon: "error" });
});
// #endif
},
onHide: function () {},
methods: {
initFn(data) {
uni.hideLoading(); // Loading
// uni.showModal({
// title: 'initFn',
// content: data || ' initFn',
// showCancel: true,
// success: function (res) {},
// });
console.log("%c%s", "color:red", "init");
console.log(data, "data--");
uni.setStorageSync(
"token",
"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9zaWQiOiIwOGRkNzFiZC01N2MxLTQ1YmMtODBiYS0xMjkzYjU4MTViMmEiLCJ1bmlxdWVfbmFtZSI6IuS_nea0gSIsInJvbGUiOiJVc2VyIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbW9iaWxlcGhvbmUiOiIxODE3NDAxMDU2MiIsImdyb3Vwc2lkIjoiNGIyZDk2NjItYTc2OC0wOGYyLWEwYzgtNzYyYjhjNzZkYTJhIiwibmJmIjoxNzQ0MjQ3MTcwLCJleHAiOjE3NDQyNTA3NzAsImlhdCI6MTc0NDI0NzE3MH0.ljZeF0Q1H8rMeh69x2N6e_qID_Y72KwmXQ1-tlOGTYc"
);
// res: {hasUpdate: true, version: 1.0.0}
updateManager.onCheckForUpdate(function (res) {
if (res.hasUpdate) { //
uni.showLoading({title:'更新中...'}); // Loading
}
});
//
updateManager.onUpdateReady(function () {
uni.hideLoading(); // Loading
uni.showModal({ //
title:'更新提示',
content:'更新完毕,是否重启?',
success:function (res) {
if (res.confirm) {
updateManager.applyUpdate(); // 使
}
}
})
});
//
updateManager.onUpdateFailed(function () {
uni.hideLoading(); // Loading
uni.showToast({ title:'更新失败,稍后再试...', icon:"error" });
});
// #endif
},
onHide: function() {
}
}
uni.switchTab({
url: "/pages/index/index",
success() {
console.log("跳转成功");
},
fail(err) {
console.error("跳转失败", err);
},
});
},
},
};
</script>
<style lang="scss">
@import "@/uni_modules/uview-ui/index.scss";
@import "@/uni_modules/uview-ui/index.scss";
</style>

View File

@ -1,6 +1,6 @@
{
"name" : "巡检保洁",
"appid" : "",
"appid" : "__UNI__659FDE6",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
@ -87,6 +87,6 @@
"uniStatistics" : {
"enable" : false
},
"sassImplementationName": "node-sass",
"sassImplementationName" : "node-sass",
"vueVersion" : "2"
}

7
node_modules/.package-lock.json generated vendored Normal file
View File

@ -0,0 +1,7 @@
{
"name": "巡检保洁",
"version": "1.0.6",
"lockfileVersion": 2,
"requires": true,
"packages": {}
}

View File

@ -4,6 +4,12 @@
"^u-(.*)": "@/uni_modules/uview-ui/components/u-$1/u-$1.vue"
},
"pages": [
{
"path": "pages/home/index",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/index/index",
"style": {

27
pages/home/index.vue Normal file
View File

@ -0,0 +1,27 @@
<template>
<view class="content"> </view>
</template>
<script>
import { useRouter } from "@/utils/utils.js";
import daySelect from "@/components/daySelect/index.vue";
export default {
components: {
daySelect,
},
data() {
return {
};
},
mounted() {
// console.log("%c%s", "color:red", "mounted--");
},
methods: {},
};
</script>
<style lang="scss" scoped>
.content {
// height: 100vh; //
overflow: hidden;
padding-bottom: 100rpx;
}
</style>

View File

@ -53,6 +53,35 @@
</view>
</view>
</view>
<button @click="nfcResFn">
{{errorShow}}
</button>
<!-- nfc刷卡成功弹窗 -->
<u-popup v-model="successShow" mode="center" :round="30" >
<view class="success-box">
<view class="box-content">
<view class="logo"></view>
<view class="content-title">刷卡成功</view>
<view class="btn-box">
<view class="btn-cancel" @click="successShow = false">暂不</view>
<view class="btn-success" @click="uploadFn">上传图片</view>
</view>
</view>
</view>
</u-popup>
<!-- nfc刷卡失败弹窗 -->
<u-popup v-model="errorShow" mode="center" :round="30" >
<view class="error-box">
<view class="box-content">
<view class="logo"></view>
<view class="content-title">刷卡失败</view>
<view class="btn-box">
<view class="btn-cancel" @click="errorShow = false">暂不</view>
<view class="btn-success" @click="exceptionReportFn">异常上报</view>
</view>
</view>
</view>
</u-popup>
</view>
</template>
@ -95,18 +124,46 @@ export default {
],
paramsId: "",
//
successShow:false,
//
errorShow:false,
};
},
onLoad(options) {
this.paramsId = options.id;
window.nfcFn = this.nfcResFn;
// this.nfcResFn();
},
created() {
this.getPlanInfoAreaList();
// this.getPlanInfoAreaList();
},
methods: {
nfcResFn(data){
if(false){
console.log('%c%s', 'color:red', 'nfc刷卡成功');
this.successShow = true;
}else{
console.log('%c%s', 'color:red', '刷卡失败');
this.errorShow = true;
}
},
//
uploadFn(){
console.log('%c%s', 'color:red', '上传图片');
uni.navigateTo({
url: "/pages/index/uploadPhoto",
});
},
//
exceptionReportFn(){
console.log('%c%s', 'color:red', '异常上报');
},
openFn(){},
closeFn(){},
changeTab(i) {
console.log(i);
this.selectIdx = i;
@ -244,4 +301,128 @@ export default {
}
}
}
.success-box{
// overflow:hidden;
width:650rpx;
padding-top:50rpx;
background-color:transparent;
.box-content{
height:450rpx;
background-color: #ffffff;
background: linear-gradient(to bottom, #A7DAFC, white 60%, white);
border-radius:30rpx;
// border:1px solid red;
position:relative;
.logo{
position:absolute;
top:-50rpx;
left:50%;
transform:translateX(-50%);
width:200rpx;
height:200rpx;
background-color:red;
}
.content-title{
position:absolute;
top:40%;
width:100%;
color:black;
font-size:40rpx;
text-align:center;
}
.btn-box{
position:absolute;
bottom:10%;
width:100%;
display:flex;
justify-content:space-evenly;
.btn-cancel{
width:200rpx;
height:70rpx;
background-color:#F3F6F7;
border-radius:50rpx;
display:flex;
align-items:center;
justify-content:center;
font-size:30rpx;
color:#32353B;
}
.btn-success{
width:200rpx;
height:70rpx;
background-color:#4278F4;
border-radius:50rpx;
display:flex;
align-items:center;
justify-content:center;
font-size:30rpx;
color:white;
}
}
}
}
.error-box{
// overflow:hidden;
width:650rpx;
padding-top:50rpx;
background-color:transparent;
.box-content{
height:450rpx;
background-color: #ffffff;
background: linear-gradient(to bottom, #A7DAFC, white 60%, white);
border-radius:30rpx;
// border:1px solid red;
position:relative;
.logo{
position:absolute;
top:-50rpx;
left:50%;
transform:translateX(-50%);
width:200rpx;
height:200rpx;
background-color:red;
}
.content-title{
position:absolute;
top:40%;
width:100%;
color:black;
font-size:40rpx;
text-align:center;
}
.btn-box{
position:absolute;
bottom:10%;
width:100%;
display:flex;
justify-content:space-evenly;
.btn-cancel{
width:200rpx;
height:70rpx;
background-color:#F3F6F7;
border-radius:50rpx;
display:flex;
align-items:center;
justify-content:center;
font-size:30rpx;
color:#32353B;
}
.btn-success{
width:200rpx;
height:70rpx;
background-color:#4278F4;
border-radius:50rpx;
display:flex;
align-items:center;
justify-content:center;
font-size:30rpx;
color:white;
}
}
}
}
::v-deep .u-mode-center-box{
margin-top:-500rpx !important;
background-color:transparent !important;
}
</style>

View File

@ -128,11 +128,14 @@ export default {
},
mounted() {
console.log('%c%s', 'color:red', 'mounted--')
this.getPlanByDate();
},
methods: {
onDateChange({ date, isToday }) {
//
// return
this.isToday = isToday;
this.currentDate = date;
this.getPlanByDate();

133
pages/index/nfc.js Normal file
View File

@ -0,0 +1,133 @@
// if ('nfc' in navigator) {
// console.log('设备支持NFC');
// uni.showToast({ title: '支持NFC', icon: "none" });
// } else {
// uni.showToast({ title: '设备不支持NFC', icon: "none" });
// console.log('设备不支持NFC');
// }
// try {
// await navigator.permissions.query({ name: 'nfc' });
// this.nfcMsg = 'NFC权限已授予'
// console.log('NFC权限已授予');
// } catch (error) {
// this.nfcMsg = '获取NFC权限失败'
// console.error('获取NFC权限失败', error);
// }
document.addEventListener("plusready", function () {
// NFC监听
monitorNFC()
})
function monitorNFC(t) {
this.nfcMsg = '111'
let NfcAdapter;
let NdefRecord;
let NdefMessage;
function listenNFCStatus() {
try {
let main = plus.android.runtimeMainActivity();
let Intent = plus.android.importClass('android.content.Intent');
let Activity = plus.android.importClass('android.app.Activity');
let PendingIntent = plus.android.importClass('android.app.PendingIntent');
let IntentFilter = plus.android.importClass('android.content.IntentFilter');
NfcAdapter = plus.android.importClass('android.nfc.NfcAdapter');
let nfcAdapter = NfcAdapter.getDefaultAdapter(main);
let intent = new Intent(main, main.getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
let pendingIntent = PendingIntent.getActivity(main, 0, intent, 0);
let ndef = new IntentFilter("android.nfc.action.TECH_DISCOVERED");
ndef.addDataType("*/*");
let intentFiltersArray = [ndef];
let techListsArray = [
["android.nfc.tech.IsoDep"],
["android.nfc.tech.NfcA"],
["android.nfc.tech.NfcB"],
["android.nfc.tech.NfcF"],
["android.nfc.tech.Nfcf"],
["android.nfc.tech.NfcV"],
["android.nfc.tech.NdefFormatable"],
["android.nfc.tech.MifareClassic"],
["android.nfc.tech.MifareUltralight"]
];
document.addEventListener("newintent",
function () {
console.error('newintent');
setTimeout(handle_nfc_data1, 1000);
}, false);
document.addEventListener("pause", function (e) {
if (nfcAdapter) {
nfcAdapter.disableForegroundDispatch(main);
console.log('pause');
}
}, false);
document.addEventListener("resume", function (e) {
if (nfcAdapter) {
console.log('resume');
nfcAdapter.enableForegroundDispatch(main, pendingIntent, intentFiltersArray, techListsArray);
}
}, false);
nfcAdapter.enableForegroundDispatch(main, pendingIntent, intentFiltersArray, techListsArray);
} catch (e) {
console.error(e);
}
}
function handle_nfc_data1() {
NdefRecord = plus.android.importClass("android.nfc.NdefRecord");
NdefMessage = plus.android.importClass("android.nfc.NdefMessage");
let main = plus.android.runtimeMainActivity();
let intent = main.getIntent();
if ("android.nfc.action.TECH_DISCOVERED" == intent.getAction()) {
// if (readyWriteData) {
// __write(intent);
// readyWriteData = false;
// } else if (readyRead) {
console.log("进行读取NFC")
__read(intent);
readyRead = false;
// }
}
}
function __read(intent) {
try {
let content = "";
waiting = plus.nativeUI.showWaiting("请勿移开标签\n正在读取数据...");
let tag = plus.android.importClass("android.nfc.Tag");
tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
let bytesId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
let rawmsgs = intent.getParcelableArrayExtra("android.nfc.extra.NDEF_MESSAGES");
let records = rawmsgs[0].getRecords();
let result = records[0].getPayload();
let s = plus.android.newObject("java.lang.String", result);
console.log(s)
if (s) {
s = s.slice(s.indexOf('en') + 2)
}
console.log('查询解过:' + s)
// console.log("bytesId:" + (bytesId));
// console.log("十六进制ID:" + (bytesToHexString(tag.getId())));
} catch (e) {
alert(e);
}
readyRead = false
waiting.close();
}
function bytesToHexString(inarray) {
let i, j, x;
let hex = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
"B", "C", "D", "E", "F"
];
let out = "";
for (j = 0; j < inarray.length; ++j) {
x = parseInt(inarray[j]) & 0xff;
i = (x >> 4) & 0x0f;
out += hex[i];
i = x & 0x0f;
out += hex[i];
}
return out;
}
}

View File

@ -8,7 +8,7 @@ const manager = new RequestManager()
// 先写死调接口
uni.setStorageSync('token', 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9zaWQiOiIwOGRkNzFiZC01N2MxLTQ1YmMtODBiYS0xMjkzYjU4MTViMmEiLCJ1bmlxdWVfbmFtZSI6IuS_nea0gSIsInJvbGUiOiJVc2VyIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvbW9iaWxlcGhvbmUiOiIxODE3NDAxMDU2MiIsImdyb3Vwc2lkIjoiNGIyZDk2NjItYTc2OC0wOGYyLWEwYzgtNzYyYjhjNzZkYTJhIiwibmJmIjoxNzQ0MTc1MjA2LCJleHAiOjE3NDQxNzg4MDYsImlhdCI6MTc0NDE3NTIwNn0.1qDnEAJH-bJlEr1wbwjTfqLY9xAyJKzf6bmLP6svUNo')
// uni.setStorageSync('token', 'Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJodHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA1LzA1L2lkZW50aXR5L2NsYWltcy9zaWQiOiI1YmJiYTBhMi04YmJmLTcxMmUtMjMxMy1kYTc0N2E1MGUxYzEiLCJ1bmlxdWVfbmFtZSI6Iua1i-ivlSIsInJvbGUiOiJBZG1pbiIsImh0dHA6Ly9zY2hlbWFzLnhtbHNvYXAub3JnL3dzLzIwMDUvMDUvaWRlbnRpdHkvY2xhaW1zL21vYmlsZXBob25lIjoiMTgxNzQwMTA1NjEiLCJncm91cHNpZCI6IjRiMmQ5NjYyLWE3NjgtMDhmMi1hMGM4LTc2MmI4Yzc2ZGEyYSIsIm5iZiI6MTc0NDE3OTY2NiwiZXhwIjoxNzQ0MTgzMjY2LCJpYXQiOjE3NDQxNzk2NjZ9.TTLt3vwefdrd8rx3zNN4rr0OI4yp14m781N3PC3lIHw')
const baseRequest = async (url, method, data = {}, loading = true) =>{