feat: 优化模板

This commit is contained in:
陶林 2023-09-07 15:13:43 +08:00
parent 1250349b9d
commit 3e05196fc5
5 changed files with 196 additions and 6 deletions

View File

@ -1,5 +1,4 @@
# 已安装的插件
## 功能
- 修改名称
- 修改包名
1. cordova-plugin-device
获取设备信息

View File

@ -3,7 +3,7 @@
<name>APP</name>
<description>app</description>
<author email="dev@cordova.apache.org" href="https://cordova.apache.org"></author>
<content src="http://10.1.23.61:10001/"/>
<content src="index.html" />
<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="tel:*"/>

27
package-lock.json generated
View File

@ -17,11 +17,13 @@
},
"devDependencies": {
"cordova-android": "^10.1.2",
"cordova-plugin-app-version": "^0.1.14",
"cordova-plugin-battery-status": "^2.0.3",
"cordova-plugin-camera": "^6.0.0",
"cordova-plugin-device": "^2.1.0",
"cordova-plugin-dialogs": "^2.0.2",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-file-opener2": "^4.0.0",
"cordova-plugin-file-transfer-jsg": "^2.0.0",
"cordova-plugin-geolocation": "^4.1.0",
"cordova-plugin-inappbrowser": "^5.0.0",
@ -1253,6 +1255,12 @@
"node": ">=12"
}
},
"node_modules/cordova-plugin-app-version": {
"version": "0.1.14",
"resolved": "https://registry.npmmirror.com/cordova-plugin-app-version/-/cordova-plugin-app-version-0.1.14.tgz",
"integrity": "sha512-HN6Yz6IIdRO+iMvCHN/qMe8/O4miOpHH/pDtWNjIYTjV3MzP+XdzFJoFnq2zxlNNXFz0Zn8REGQhFY77vV4AWQ==",
"dev": true
},
"node_modules/cordova-plugin-battery-status": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/cordova-plugin-battery-status/-/cordova-plugin-battery-status-2.0.3.tgz",
@ -1344,6 +1352,25 @@
}
}
},
"node_modules/cordova-plugin-file-opener2": {
"version": "4.0.0",
"resolved": "https://registry.npmmirror.com/cordova-plugin-file-opener2/-/cordova-plugin-file-opener2-4.0.0.tgz",
"integrity": "sha512-+O+MMldI2k5Kjoa62KXYxnZQIGE4k5VfoCmmOUmaV5XM6U6euiiKMfCkuMrOrdAFb1C5Jsx+SuBHbWx1NEB5lw==",
"dev": true,
"engines": {
"cordovaDependencies": {
"2.0.0": {
"cordova": ">=6.0.0"
},
"3.0.0": {
"cordova": ">=7.0.0"
},
"4.0.0": {
"cordova-android": ">=10.0.0"
}
}
}
},
"node_modules/cordova-plugin-file-transfer-jsg": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/cordova-plugin-file-transfer-jsg/-/cordova-plugin-file-transfer-jsg-2.0.0.tgz",

View File

@ -19,11 +19,13 @@
"license": "Apache-2.0",
"devDependencies": {
"cordova-android": "^10.1.2",
"cordova-plugin-app-version": "^0.1.14",
"cordova-plugin-battery-status": "^2.0.3",
"cordova-plugin-camera": "^6.0.0",
"cordova-plugin-device": "^2.1.0",
"cordova-plugin-dialogs": "^2.0.2",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-file-opener2": "^4.0.0",
"cordova-plugin-file-transfer-jsg": "^2.0.0",
"cordova-plugin-geolocation": "^4.1.0",
"cordova-plugin-inappbrowser": "^5.0.0",
@ -69,7 +71,9 @@
"cordova-plugin-printer-jsg": {
"ANDROID_SUPPORT_V4_VERSION": "28.+"
},
"cordova-plugin-file-transfer-jsg": {}
"cordova-plugin-file-transfer-jsg": {},
"cordova-plugin-app-version": {},
"cordova-plugin-file-opener2": {}
}
},
"dependencies": {

View File

@ -0,0 +1,160 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="initial-scale=1, width=device-width, viewport-fit=cover"
/>
<title>Hello World</title>
<script src="cordova.js"></script>
<!-- 导入样式 -->
<link rel="stylesheet" href="//unpkg.com/element-plus/dist/index.css" />
<!-- 导入 Vue 3 -->
<script src="//unpkg.com/vue@next"></script>
<!-- 导入组件库 -->
<script src="//unpkg.com/element-plus"></script>
</head>
<body>
<div id="app">
<h1>Cordova plugins</h1>
<el-button @click="getDeviceInfo">获取设备信息</el-button>
<el-button @click="openUrl">打开百度</el-button>
<el-button @click="deviceVibration">设备震动</el-button>
<el-button @click="scanCode">扫码</el-button>
<el-button @click="takPhoto">拍照</el-button>
<el-button @click="docPrint">文件打印</el-button>
<el-button @click="versionCheck">版本升级</el-button>
<el-button @click="installAPK" type="danger">安装apk</el-button>
</div>
</body>
<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script>
<script>
var vConsole = new window.VConsole();
</script>
<script>
const app = Vue.createApp({
mounted() {
setTimeout(() => {
window.addEventListener("batterystatus", this.onBatteryStatus, false);
}, 600);
},
methods: {
installAPK() {
let url = "http://3000.taoya.art/app.apk";
var filename = url.split("/").pop();
var targetPath = cordova.file.externalRootDirectory + filename;
console.log(cordova.file.externalRootDirectory);
//1. 下载
let _this = this;
_this.progress = 0;
_this.fileTransfer = new FileTransfer();
_this.fileTransfer.onprogress = function (e) {
if (e.lengthComputable) {
const progress = e.loaded / e.total;
_this.progress = (progress * 100).toFixed(2);
console.log(progress);
}
};
console.log("download file");
_this.fileTransfer.download(
encodeURI(url), //服务器地址
targetPath, //本地存储地址
function (entry) {
//下载完成回调
let url = entry.toURL();
console.log(url);
},
function (error) {
console.log(error);
_this.$message.error(error);
},
{
trustHosts: true,
}
);
return;
//2. 安装
cordova.plugins.fileOpener2.open(
"",
"application/vnd.android.package-archive",
{
error: function (e) {
console.log("open fail");
},
success: function () {
console.log("open successfully");
},
}
);
},
async versionCheck() {
let versionCode =
await window.cordova.getAppVersion.getVersionNumber();
this.$message.success(`当前版本: ${versionCode}`);
},
docPrint() {
// use
// cordova.plugins.printer.print();
cordova.plugins.printer.print("<b>Hello Cordova!</b>");
},
takPhoto() {
let that = this;
window.navigator.camera.getPicture(
(imageURI) => {
console.log(imageURI);
that.$message.success(`文件路径: ${imageURI}`);
},
(message) => {
this.$message.warning("取消拍照");
},
{
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
}
);
},
scanCode() {
cordova.plugins.barcodeScanner.scan(
function (result) {
try {
if (result.text) {
alert(result.text);
}
} catch (e) {
console.log(e);
}
},
function (error) {
that.$message.error("扫描失败");
}
);
},
onBatteryStatus(status) {
this.$message.warning(
"电池电量: " + status.level + " 是否充电中: " + status.isPlugged
);
},
deviceVibration() {
navigator.vibrate(600);
// var pattern = [1000, 1000, 1000, 1000];
// navigator.vibrate(pattern);
},
openUrl() {
var ref = cordova.InAppBrowser.open(
"https://www.baidu.com",
"_blank",
"location=yes"
);
},
getDeviceInfo() {
this.$message.success("请打开控制台查看");
console.log(window.device);
},
},
});
app.use(ElementPlus);
app.mount("#app");
</script>
</html>