提交 032c393f 编写于 作者: lizhongyi_'s avatar lizhongyi_

移除出语法测试外的示例内容

上级 3027f244
......@@ -2,7 +2,7 @@
"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
{
"path": "pages/index/index",
"path": "pages/index/basicTest",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
......@@ -16,82 +16,6 @@
"enablePullDownRefresh": false
}
},
{
"path": "pages/SystemAPI/SystemAPI",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/SystemAPI/Alert/alert",
"style": {
"navigationBarTitleText": ""
}
},
{
"path": "pages/component/helloView",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/SDKIntegration/SDKIntegration",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/SDKIntegration/TencentLocation/TencentLocation",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/SDKIntegration/Lottie/index",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/SDKIntegration/Toast/Toast",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/lifecycle/lifecycle",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/resource/resource",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/resource/fileRead",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/advance/android/decorview",
"style": {
......@@ -116,15 +40,6 @@
}
},
{
"path": "pages/SystemAPI/ScreenListen/screenlisten",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/SyntaxCase/index",
"style": {
......@@ -157,17 +72,7 @@
"enablePullDownRefresh": false
}
},
{
"path" : "pages/SyntaxCase/basicTest",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
}
],
"tabBar": {
"color": "#7A7E83",
......@@ -175,18 +80,12 @@
"borderStyle": "black",
"backgroundColor": "#F8F8F8",
"list": [{
"pagePath": "pages/index/index",
"text": "入门"
"pagePath": "pages/index/basicTest",
"text": "基础语法"
},
{
"pagePath": "pages/advance/advance",
"text": "进阶"
}, {
"pagePath": "pages/SystemAPI/SystemAPI",
"text": "系统API"
}, {
"pagePath": "pages/SDKIntegration/SDKIntegration",
"text": "三方SDK"
"text": "进阶语法"
}
]
},
......
<template>
<div>
<button @tap="changeUrl">播放本地动画资源</button>
<button @tap="changeServerUrl">播放远程动画资源</button>
<button @tap="changeAutoPlay">测试AutoPlay</button>
<button @tap="changeLoop">测试Loop</button>
<button @tap="changeAction(1)">测试action play</button>
<button @tap="changeAction(2)">测试action pause</button>
<button @tap="changeAction(3)">测试action stop</button>
<uts-animation-view ref="animView" :path="animUrl" :autoplay="autoplay" :loop="loop" :action="action"
:hidden="hidden" @bindended="testAnimEnd" @click="lottieClickTest" @longpress="lottieLongpressTest"
:style="{width:widthNum+'rpx',height:heightNum+'px',background:yanse}">
</uts-animation-view>
</div>
</template>
<script>
export default {
data() {
return {
hidden: false,
autoplay: false,
action: "play",
loop: false,
yanse: "red",
widthNum: 750,
heightNum: 200,
comShow: true,
animUrl: "/static/anim_a.json"
}
},
methods: {
changeAutoPlay: function() {
this.autoplay = !this.autoplay
},
changeUrl: function() {
if (this.animUrl == "/static/anim_a.json") {
this.animUrl = "/static/anim_b.json"
} else {
this.animUrl = "/static/anim_a.json"
}
},
changeServerUrl: function() {
this.animUrl = "https://b.bdstatic.com/miniapp/images/lottie_example_one.json"
},
changeAction: function(type) {
if (type == 1) {
this.action = "play"
} else if (type == 2) {
this.action = "pause"
} else if (type == 3) {
this.action = "stop"
}
},
changeLoop: function() {
this.loop = !this.loop
},
testAnimEnd: function(res) {
console.log("testAnimEnd");
console.log(res);
},
changeRepeat: function(res) {
this.$refs["animView"].updateRepeatConfig("RESTART");
},
lottieClickTest: function(res) {
console.log("lottieClickTest");
console.log(res);
},
lottieLongpressTest: function(res) {
console.log("lottieClickTest");
console.log(res);
},
}
}
</script>
<template>
<div>
<button @tap="changeUrl">播放本地动画资源</button>
<button @tap="changeServerUrl">播放远程动画资源</button>
<button @tap="changeAutoPlay">测试AutoPlay</button>
<button @tap="changeLoop">测试Loop</button>
<button @tap="changeAction(1)">测试action play</button>
<button @tap="changeAction(2)">测试action pause</button>
<button @tap="changeAction(3)">测试action stop</button>
<!-- <uts-animation-view ref="animView" :path="animUrl" :autoplay="autoplay" :loop="loop" :action="action"
:hidden="hidden" @bindended="testAnimEnd" @click="lottieClickTest" @longpress="lottieLongpressTest"
:style="{width:widthNum+'rpx',height:heightNum+'px',background:yanse}">
</uts-animation-view> -->
</div>
</template>
<script lang="ts">
export default {
data() {
return {
hidden: false,
autoplay: false,
action: "play",
loop: false,
yanse: "red",
widthNum: 750,
heightNum: 200,
comShow: true,
animUrl: "/static/anim_a.json"
}
},
methods: {
changeAutoPlay: function() {
this.autoplay = !this.autoplay
},
changeUrl: function() {
if (this.animUrl == "/static/anim_a.json") {
this.animUrl = "/static/anim_b.json"
} else {
this.animUrl = "/static/anim_a.json"
}
},
changeServerUrl: function() {
this.animUrl = "https://b.bdstatic.com/miniapp/images/lottie_example_one.json"
},
changeAction: function(type: number) {
if (type == 1) {
this.action = "play"
} else if (type == 2) {
this.action = "pause"
} else if (type == 3) {
this.action = "stop"
}
},
changeLoop: function() {
this.loop = !this.loop
},
testAnimEnd: function() {
console.log("testAnimEnd");
},
changeRepeat: function() {
// this.$refs["animView"].updateRepeatConfig("RESTART");
},
lottieClickTest: function() {
console.log("lottieClickTest");
},
lottieLongpressTest: function() {
console.log("lottieClickTest");
},
}
}
</script>
<template>
<view class="uni-container">
<page-head :title="title"></page-head>
<view class="uni-panel" v-for="(item, index) in list" :key="index">
<view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="goDetailPage(item)"
hover-class="uni-navigate-item-active">
<text class="uni-panel-text">{{item.name}}</text>
<image :src="arrowRightIcon" class="uni-icon"></image>
</view>
</view>
</view>
</template>
<script lang="ts">
// import {
// checkHasIntegration
// } from "@/uni_modules/uts-tencentgeolocation";
// import {
// checkHasLottieIntegration
// } from "@/uni_modules/uts-animation-view";
type ListItem = {
name : string,
open : boolean,
function ?: string,
url ?: string
}
export default {
data() {
return {
title: 'SDK集成示例',
list: [{
name: "腾讯定位sdk集成示例",
function: "gotoTencentLocation"
},
{
name: "Toast示例",
url: "SDKIntegration/Toast/Toast"
},
{
name: "Lottie动画示例",
function: "gotoLottie"
}
] as ListItem[],
arrowRightIcon: '/static/icons/arrow-right.png',
}
},
methods: {
goDetailPage(e : ListItem) {
if (e.function != null) {
const funName = e.function
switch (funName) {
case 'gotoTencentLocation':
this.gotoTencentLocation()
break
case 'gotoLottie':
this.gotoLottie()
break
}
return
}
uni.navigateTo({
url: `/pages/${e.url!}`
})
},
gotoLottie: function () {
// if (checkHasLottieIntegration()) {
// uni.navigateTo({
// url: '/pages/SDKIntegration/Lottie/index'
// })
// } else {
// uni.showToast({
// icon: 'none',
// title: '需要在自定义基座中运行'
// })
// }
},
gotoTencentLocation: function () {
// let ret = checkHasIntegration();
// if (!ret) {
// uni.showToast({
// icon: 'none',
// title: '需要在自定义基座中运行'
// })
// } else {
// uni.navigateTo({
// url: '/pages/SDKIntegration/TencentLocation/TencentLocation'
// })
// }
},
gotoTencentMap: function () {
uni.navigateTo({
url: '/pages/SDKIntegration/TencentMap/TencentMap'
})
}
}
}
</script>
<style>
@import '@/common/uni-uvue.css';
</style>
\ No newline at end of file
<template>
<view class="uni-container">
<page-head :title="title"></page-head>
<view class="uni-panel" v-for="(item, index) in list" :key="index">
<view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="goDetailPage(item)" hover-class="uni-navigate-item-active">
<text class="uni-panel-text">{{item.name}}</text>
<image :src="arrowRightIcon" class="uni-icon"></image>
</view>
</view>
</view>
</template>
<script>
import {
checkHasIntegration
} from "@/uni_modules/uts-tencentgeolocation";
import {
checkHasLottieIntegration
} from "@/uni_modules/uts-animation-view";
export default {
data() {
return {
title: 'SDK集成示例',
list: [{
name: "腾讯定位sdk集成示例",
function: "gotoTencentLocation"
},
{
name: "Toast示例",
url: "SDKIntegration/Toast/Toast"
},
{
name: "Lottie动画示例",
function: "gotoLottie"
}
],
arrowRightIcon: '/static/icons/arrow-right.png',
}
},
methods: {
goDetailPage(e) {
if (e.function) {
this[e.function]()
return
}
uni.navigateTo({
url: `/pages/${e.url}`
})
},
gotoLottie: function(e) {
if (checkHasLottieIntegration()) {
uni.navigateTo({
url: '/pages/SDKIntegration/Lottie/index'
})
} else {
uni.showToast({
icon: 'none',
title: '需要在自定义基座中运行'
})
}
},
gotoTencentLocation: function(e) {
let ret = checkHasIntegration();
if (!ret) {
uni.showToast({
icon: 'none',
title: '需要在自定义基座中运行'
})
} else {
uni.navigateTo({
url: '/pages/SDKIntegration/TencentLocation/TencentLocation'
})
}
},
gotoTencentMap: function(e) {
uni.navigateTo({
url: '/pages/SDKIntegration/TencentMap/TencentMap'
})
}
}
}
</script>
<style>
@import '@/common/uni-uvue.css';
.uni-container {
min-height: 100%;
}
</style>
\ No newline at end of file
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
1. 腾讯定位sdk需在腾讯地图官网申请key。 https://lbs.qq.com/
</view>
<view class="uni-hello-text">
2. 按照readme文档配置apikey
</view>
<view class="uni-hello-text">
3. 需要制作自定义基座运行
</view>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="checkLocationPermission">请求定位权限</button>
<button type="primary" @tap="testGetlocation">获取设备位置信息</button>
<button type="primary" @tap="testWatchPosition">监听设备位置信息</button>
<button type="primary" @tap="testClearWatch">停止监听</button>
</view>
</view>
</template>
<script>
// import {
// checkHasIntegration,
// requestPremission,
// getLocation,
// watchPosition,
// clearWatch
// } from "../../../uni_modules/uts-tencentgeolocation";
export default {
data() {
return {
title: '腾讯定位SDK集成示例',
}
},
methods: {
checkLocationPermission: function() {
// requestPremission();
},
testGetlocation: function() {
// let startRet = getLocation({
// geocode: true,
// success: function(response) {
// console.log(response);
// var addressDesc = response.name + '-' + response.address
// uni.showToast({
// title: '执行结果:' + addressDesc,
// icon: 'none'
// });
// },
// fail: function(msg) {
// uni.showToast({
// title: msg,
// icon: "none"
// })
// }
// })
// if (!startRet) {
// uni.showToast({
// title: '定位启动失败,请检查配置',
// icon: 'none'
// });
// }
},
testWatchPosition() {
// watchPosition({
// geocode: true,
// success: function(response) {
// console.log(response);
// var addressDesc = response.name + '-' + response.address
// uni.showToast({
// title: '执行结果:' + addressDesc,
// icon: 'none'
// });
// },
// fail: function(msg) {
// uni.showToast({
// title: msg,
// icon: "none"
// })
// }
// })
},
testClearWatch() {
// clearWatch()
}
}
}
</script>
<style>
</style>
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
1. 腾讯定位sdk需在腾讯地图官网申请key。 https://lbs.qq.com/
</view>
<view class="uni-hello-text">
2. 按照readme文档配置apikey
</view>
<view class="uni-hello-text">
3. 需要制作自定义基座运行
</view>
</view>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="checkLocationPermission">请求定位权限</button>
<button type="primary" @tap="testGetlocation">获取设备位置信息</button>
<button type="primary" @tap="testWatchPosition">监听设备位置信息</button>
<button type="primary" @tap="testClearWatch">停止监听</button>
</view>
</view>
</template>
<script>
import {
checkHasIntegration,
requestPremission,
getLocation,
watchPosition,
clearWatch
} from "@/uni_modules/uts-tencentgeolocation";
export default {
data() {
return {
title: '腾讯定位SDK集成示例',
}
},
methods: {
checkLocationPermission: function(e) {
requestPremission();
},
testGetlocation: function(e) {
let startRet = getLocation({
geocode: true,
success: function(response) {
console.log(response);
var addressDesc = response.name + '-' + response.address
uni.showToast({
title: '执行结果:' + addressDesc,
icon: 'none'
});
},
fail: function(msg) {
uni.showToast({
title: msg,
icon: "none"
})
}
})
if (!startRet) {
uni.showToast({
title: '定位启动失败,请检查配置',
icon: 'none'
});
}
},
testWatchPosition() {
watchPosition({
geocode: true,
success: function(response) {
console.log(response);
var addressDesc = response.name + '-' + response.address
uni.showToast({
title: '执行结果:' + addressDesc,
icon: 'none'
});
},
fail: function(msg) {
uni.showToast({
title: msg,
icon: "none"
})
}
})
},
testClearWatch() {
clearWatch()
}
}
}
</script>
<style>
</style>
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
1.Android 平台需要自定义基座运行
</view>
</view>
<view class="uni-padding-wrap uni-common-mt">
<button @tap="testToastShow">调用 Toast 弹窗</button>
</view>
</view>
</template>
<script>
import { showToast } from '@/uni_modules/uts-toast'
export default {
data() {
return {
title:"Toast 示例"
}
},
methods:{
testToastShow(){
let ret = showToast();
if(!ret){
uni.showToast({
icon:'none',
title:'需要在自定义基座中运行'
})
}
}
}
}
</script>
<style>
</style>
\ No newline at end of file
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
1.Android 平台需要自定义基座运行
</view>
</view>
<view class="uni-padding-wrap uni-common-mt">
<button @tap="testToastShow">调用 Toast 弹窗</button>
</view>
</view>
</template>
<script>
import { showToast } from '@/uni_modules/uts-toast'
export default {
data() {
return {
title:"Toast 示例"
}
},
methods:{
testToastShow(){
let ret = showToast();
if(!ret){
uni.showToast({
icon:'none',
title:'需要在自定义基座中运行'
})
}
}
}
}
</script>
<style>
</style>
\ No newline at end of file
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<button @tap="testShowAlert">确认框</button>
<button @tap="testShowPrompt">输入框</button>
</view>
</view>
</template>
<script>
import { showAlert,showPrompt } from '@/uni_modules/uts-alert'
export default {
data() {
return {
title:"Alert 示例"
}
},
methods:{
testShowAlert(){
showAlert("提示框","这是一个提示框", (index)=> {
let title:string
if (index == 0) {
title = "点击了确认"
} else{
title = "点击了取消"
}
uni.showToast({
title: title,
icon:'none'
})
})
},
testShowPrompt() {
showPrompt("输入框","这是一个输入框","请输入内容", (content)=>{
let title = content.length > 0 ? content : "没有输入内容"
uni.showToast({
title: title,
icon:'none'
})
})
}
}
}
</script>
<style>
</style>
\ No newline at end of file
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<button @tap="testShowAlert">确认框</button>
<button @tap="testShowPrompt">输入框</button>
</view>
</view>
</template>
<script>
import { showAlert,showPrompt } from '@/uni_modules/uts-alert'
export default {
data() {
return {
title:"Alert 示例"
}
},
methods:{
testShowAlert(){
showAlert("提示框","这是一个提示框", (index)=> {
var title = null
if (index == 0) {
title = "点击了确认"
} else{
title = "点击了取消"
}
uni.showToast({
title: title,
icon:'none'
})
})
},
testShowPrompt() {
showPrompt("输入框","这是一个输入框","请输入内容", (content)=>{
let title = content.length > 0 ? content : "没有输入内容"
uni.showToast({
title: title,
icon:'none'
})
})
}
}
}
</script>
<style>
</style>
\ No newline at end of file
<template>
<view>
<page-head title="监听系统截屏" accordion></page-head>
<button @click="testScreenShotListen">监听截屏事件</button>
<button @click="testScreenShotOff">关闭截屏监听</button>
<image :src="screenImage" mode="aspectFit" style="margin-top:10px"></image>
</view>
</template>
<script>
import {
onUserCaptureScreen,
offUserCaptureScreen
} from "@/uni_modules/uts-screenshot-listener";
export default {
data() {
return {
screenImage:""
}
},
methods: {
testScreenShotListen() {
var that = this;
onUserCaptureScreen(function(res) {
console.log(res);
if (uni.getSystemInfoSync().platform == "android") {
// 除android 之外的平台,不需要判断返回状态码
if(res.errCode == -1){
// 启动失败
return ;
}else if(res.errCode == 0){
uni.showToast({
icon:"none",
title:'截屏监听已开启'
})
}else {
uni.showToast({
icon:"none",
title:'捕获截屏事件'
})
if (res.image != null) {
that.screenImage = res.image!
}
}
}else{
// 除android 之外的平台,不需要判断返回状态码
uni.showToast({
icon:"none",
title:'捕获截屏事件'
})
}
});
if (uni.getSystemInfoSync().platform != "android") {
// 除android 之外的平台,直接提示监听已开启
uni.showToast({
icon:"none",
title:'截屏监听已开启'
})
}
},
testScreenShotOff() {
var that = this;
offUserCaptureScreen(function(res) {
console.log(res);
});
// 提示已经开始监听,注意观察
uni.showToast({
icon:"none",
title:'截屏监听已关闭'
})
},
}
}
</script>
<style>
</style>
\ No newline at end of file
<template>
<view>
<page-head title="监听系统截屏" accordion></page-head>
<button @click="testScreenShotListen">监听截屏事件</button>
<button @click="testScreenShotOff">关闭截屏监听</button>
<image :src="screenImage" mode="aspectFit" style="margin-top:10px"></image>
</view>
</template>
<script>
import {
onUserCaptureScreen,
offUserCaptureScreen
} from "@/uni_modules/uts-screenshot-listener";
export default {
data() {
return {
screenImage:""
}
},
methods: {
testScreenShotListen() {
var that = this;
onUserCaptureScreen(function(res) {
console.log(res);
if (uni.getSystemInfoSync().platform == "android") {
// 除android 之外的平台,不需要判断返回状态码
if(res.errCode == -1){
// 启动失败
return ;
}else if(res.errCode == 0){
uni.showToast({
icon:"none",
title:'截屏监听已开启'
})
}else {
uni.showToast({
icon:"none",
title:'捕获截屏事件'
})
that.screenImage = res.image
}
}else{
// 除android 之外的平台,不需要判断返回状态码
uni.showToast({
icon:"none",
title:'捕获截屏事件'
})
}
});
if (uni.getSystemInfoSync().platform != "android") {
// 除android 之外的平台,直接提示监听已开启
uni.showToast({
icon:"none",
title:'截屏监听已开启'
})
}
},
testScreenShotOff() {
var that = this;
offUserCaptureScreen(function(res) {
console.log(res);
});
// 提示已经开始监听,注意观察
uni.showToast({
icon:"none",
title:'截屏监听已关闭'
})
},
}
}
</script>
<style>
</style>
\ No newline at end of file
<template>
<view class="uni-container">
<page-head :title="title"></page-head>
<view class="uni-panel" v-for="(item, index) in list" :key="index">
<view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index)">
<text class="uni-panel-text">{{item.name}}</text>
<image :src="item.pages.length > 0 ? item.open ? arrowUpIcon : arrowDownIcon : arrowRightIcon"
class="uni-icon"></image>
</view>
<view class="uni-panel-c" v-if="item.open">
<view class="uni-navigate-item" v-for="(page,key) in item.pages" :key="key" @click="goDetailPage(page)" hover-class="uni-navigate-item-active">
<text class="uni-navigate-text">{{page.name}}</text>
<image :src="arrowRightIcon" class="uni-icon" v-if="page.url"></image>
</view>
</view>
</view>
</view>
</template>
<script lang="ts">
import { gotoDemoActivity } from "@/uni_modules/uts-nativepage";
import { getBatteryInfo, GetBatteryInfoOptions } from "@/uni_modules/uts-getbatteryinfo";
type Page = {
name : string,
url ?: string
function ?: string
}
type ListItem = {
name : string,
open : boolean,
pages : Page[],
}
export default {
data() {
return {
title: '系统API示例',
list: [{
name: "设备相关",
open: false,
pages: [{
name: "获取电池电量",
function: "testGetBatteryCapacity"
}] as Page[]
},
{
name: "系统事件",
open: false,
pages: [{
name: "监听系统截屏",
url: "SystemAPI/ScreenListen/screenlisten"
}] as Page[]
},
{
name: "Alert系统弹窗",
open: false,
pages: [{
name: "Alert弹窗",
url: "SystemAPI/Alert/alert"
}] as Page[]
},
{
name: "android平台",
open: false,
pages: [{
name: "自定义activity(需自定义基座)",
function: "testGotoDemoActivity"
}] as Page[]
}
] as ListItem[],
arrowUpIcon: '/static/icons/arrow-up.png',
arrowDownIcon: '/static/icons/arrow-down.png',
arrowRightIcon: '/static/icons/arrow-right.png',
}
},
methods: {
triggerCollapse(index: number) {
for (var i = 0; i < this.list.length; ++i) {
if (index == i) {
this.list[i].open = !this.list[i].open;
} else {
this.list[i].open = false;
}
}
},
goDetailPage(e: Page) {
if (e.function != null) {
const funName = e.function
switch (funName) {
case 'testGetBatteryCapacity':
this.testGetBatteryCapacity()
break
case 'testGotoDemoActivity':
this.testGotoDemoActivity()
break
}
return
}
uni.navigateTo({
url: `/pages/${e.url}`
})
},
testGetBatteryCapacity() {
getBatteryInfo({
success(res) {
uni.showToast({
title: "当前电量:" + (res as UTSJSONObject)['level'] + '%',
icon: 'none'
});
}
} as GetBatteryInfoOptions)
},
testGotoDemoActivity() {
let ret = gotoDemoActivity();
if (!ret) {
uni.showToast({
icon: 'none',
title: '需要在自定义基座中运行'
})
}
}
}
}
</script>
<style>
@import '@/common/uni-uvue.css';
</style>
\ No newline at end of file
<template>
<view class="uni-container">
<page-head :title="title"></page-head>
<view class="uni-panel" v-for="(item, index) in list" :key="index">
<view class="uni-panel-h" :class="item.open ? 'uni-panel-h-on' : ''" @click="triggerCollapse(index, item)">
<text class="uni-panel-text">{{item.name}}</text>
<image :src="item.pages.length > 0 ? item.open ? arrowUpIcon : arrowDownIcon : arrowRightIcon"
class="uni-icon"></image>
</view>
<view class="uni-panel-c" v-if="item.open">
<view class="uni-navigate-item" v-for="(page,key) in item.pages" :key="key" @click="goDetailPage(page)" hover-class="uni-navigate-item-active">
<text class="uni-navigate-text">{{page.name}}</text>
<image :src="arrowRightIcon" class="uni-icon" v-if="page.url"></image>
</view>
</view>
</view>
</view>
</template>·
<script>
import { gotoDemoActivity } from "@/uni_modules/uts-nativepage";
import { getBatteryInfo } from "@/uni_modules/uts-getbatteryinfo";
export default {
data() {
return {
title: '系统API示例',
list: [{
name: "设备相关",
open: false,
pages: [{
name: "获取电池电量",
function: "testGetBatteryCapacity"
}]
},
{
name: "系统事件",
open: false,
pages: [{
name: "监听系统截屏",
url: "SystemAPI/ScreenListen/screenlisten"
}]
},
{
name: "Alert系统弹窗",
open: false,
pages: [{
name: "Alert弹窗",
url: "SystemAPI/Alert/alert"
}]
},
{
name: "android平台",
open: false,
pages: [{
name: "自定义activity(需自定义基座)",
function: "testGotoDemoActivity"
}]
}
],
arrowUpIcon: '/static/icons/arrow-up.png',
arrowDownIcon: '/static/icons/arrow-down.png',
arrowRightIcon: '/static/icons/arrow-right.png',
}
},
methods: {
triggerCollapse(index) {
for (var i = 0; i < this.list.length; ++i) {
if (index == i) {
this.list[i].open = !this.list[i].open;
} else {
this.list[i].open = false;
}
}
},
goDetailPage(e) {
if (e.function) {
this[e.function]()
return
}
uni.navigateTo({
url: `/pages/${e.url}`
})
},
testGetBatteryCapacity() {
getBatteryInfo({
success(res) {
uni.showToast({
title: "当前电量:" + res.level + '%',
icon: 'none'
});
}
})
},
testGotoDemoActivity() {
let ret = gotoDemoActivity();
if (!ret) {
uni.showToast({
icon: 'none',
title: '需要在自定义基座中运行'
})
}
}
}
}
</script>
<style>
@import '@/common/uni-uvue.css';
.uni-container {
min-height: 100%;
}
</style>
\ No newline at end of file
......@@ -78,56 +78,6 @@
}, {
name: "实例测试示例",
url: "SyntaxCase/instanceTest"
}, {
name: "基础语法测试例",
url: "SyntaxCase/basicTest"
}] as Page[]
},
{
name: "资源加载示例",
open: false,
pages: [{
name: "图片加载示例",
url: "resource/resource"
}, {
name: "文件读取示例",
url: "resource/fileRead"
}] as Page[]
},
{
name: "组件开发示例",
open: false,
pages: [{
name: "Hello UTS Component",
url: "component/helloView"
}] as Page[]
},
{
name: "android平台示例",
open: false,
pages: [{
name: "activity生命周期监听",
url: "lifecycle/lifecycle"
}, {
name: "播放asset音频(需自定义基座)",
url: "advance/android/assetaudio"
}, {
name: "操作DecorView",
url: "advance/android/decorview"
}, {
name: "读取meta配置",
function: "testMetaRead"
}, {
name: "退出当前应用",
function: "testQuitApp"
}] as Page[]
},
{
name: "iOS平台示例",
open: false,
pages: [{
name: "资源路径获取示例",
url: "advance/iOS/getResourcePath"
}] as Page[]
},
] as ListItem[],
......
......@@ -67,56 +67,6 @@
},{
name: "实例测试示例",
url: "SyntaxCase/instanceTest"
}, {
name: "基础语法测试例",
url: "SyntaxCase/basicTest"
}]
},
{
name: "资源加载示例",
open: false,
pages: [{
name: "图片加载示例",
url: "resource/resource"
},{
name: "文件读取示例",
url: "resource/fileRead"
}]
},
{
name: "组件开发示例",
open: false,
pages: [{
name: "Hello UTS Component",
url: "component/helloView"
}]
},
{
name: "android平台示例",
open: false,
pages: [{
name: "activity生命周期监听",
url: "lifecycle/lifecycle"
}, {
name: "播放asset音频(需自定义基座)",
url: "advance/android/assetaudio"
}, {
name: "操作DecorView",
url: "advance/android/decorview"
}, {
name: "读取meta配置",
function: "testMetaRead"
}, {
name: "退出当前应用",
function: "testQuitApp"
}]
},
{
name: "iOS平台示例",
open: false,
pages: [{
name: "资源路径获取示例",
url: "advance/iOS/getResourcePath"
}]
},
],
......
<template>
<div>
<uts-hello-view buttonText="点击按钮内容" style="width:375px;height: 375px;background-color: aqua;"></uts-hello-view>
<uts-hello-container>
<text>文本组件</text>
<image src="../../static/logo.png" mode="aspectFit"></image>
</uts-hello-container>
</div>
</template>
<script>
</script>
<style>
</style>
\ No newline at end of file
<template>
<view>
<uts-hello-view buttonText="点击按钮内容" style="width:375px;height: 375px;background-color: aqua;"></uts-hello-view>
<uts-hello-container>
<text>文本组件</text>
<image src="../../static/logo.png" mode="aspectFit"></image>
</uts-hello-container>
</view>
</template>
<script>
</script>
<style>
</style>
\ No newline at end of file
<template>
<view class="content">
<view class="content">
<page-head :title="title"></page-head>
<view v-for="(item,index) in resultArray" :key="index" class="result">
<view>{{names[index]}}测试结果:</view>
<view>
......@@ -22,7 +23,8 @@
export default {
data() {
return {
return {
title: 'UTS基础语法',
resultArray: [] as Result[],
result: {} as UTSJSONObject,
names: [] as string[]
......@@ -43,8 +45,10 @@
}
}
</script>
<style>
.content {
<style>
@import '@/common/uni-uvue.css';
.content {
min-height: 100%;
padding: 32rpx;
}
......
<template>
<view class="content">
<view class="content">
<page-head :title="title"></page-head>
<view v-for="(item,name) in result" :key="name" class="result">
<view>{{name}}测试结果:</view>
<view>
......@@ -21,7 +22,8 @@
} from '../../uni_modules/uts-tests'
export default {
data() {
return {
return {
title: 'UTS基础语法',
result: {}
}
},
......@@ -36,8 +38,11 @@
}
}
</script>
<style>
.content {
<style>
@import '@/common/uni-uvue.css';
.content {
min-height: 100%;
padding: 32rpx;
}
......
<template>
<view>
<page-head :title="title"></page-head>
<input class="uni-input" v-model="stringParam" />
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="testDoSthWithCallback">uts异步方法(无参数)</button>
<button type="primary" @tap="testDoSthWithString">uts异步方法(字符串参数)</button>
<button type="primary" @tap="testDoSthWithJSON">uts异步方法(json参数)</button>
</view>
</view>
</template>
<script>
import { callWithJSONParam, callWithStringParam, callWithoutParam, JsonParamOptions, inputJSON } from "../../uni_modules/uts-helloworld";
export default {
data() {
return {
title: 'UTS入门示例',
stringParam: "hello world",
}
},
methods: {
/**
* 测试无参数调用
*/
testDoSthWithCallback: function () {
callWithoutParam(
() => {
uni.showToast({
title: '成功调用uts插件uts-helloworld的callWithoutParam',
icon: 'none'
});
}
);
},
/**
* 测试字符串参数回调
*/
testDoSthWithString: function () {
callWithStringParam(
this.stringParam,
function (response) {
uni.showToast({
title: 'uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:' + response,
icon: 'none'
});
},
);
},
/**
* 测试json参数回调
*/
testDoSthWithJSON: function () {
const that = this
var inputObject : inputJSON = {
inputText: that.stringParam,
errCode: 0
}
callWithJSONParam({
input: inputObject,
success: function (response) {
uni.showToast({
title: '执行结果:' + JSON.stringify(response),
icon: 'none'
});
}
} as JsonParamOptions);
},
}
}
</script>
<style>
</style>
\ No newline at end of file
<template>
<view>
<page-head :title="title"></page-head>
<input class="uni-input" v-model="stringParam" />
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="testDoSthWithCallback">uts异步方法(无参数)</button>
<button type="primary" @tap="testDoSthWithString">uts异步方法(字符串参数)</button>
<button type="primary" @tap="testDoSthWithJSON">uts异步方法(json参数)</button>
</view>
</view>
</template>
<script>
import { callWithJSONParam, callWithStringParam, callWithoutParam } from "../../uni_modules/uts-helloworld";
export default {
data() {
return {
title: 'UTS入门示例',
stringParam:"hello world",
}
},
methods: {
/**
* 测试无参数调用
*/
testDoSthWithCallback: function () {
callWithoutParam(
()=>{
uni.showToast({
title:'成功调用uts插件uts-helloworld的callWithoutParam',
icon:'none'
});
}
);
},
/**
* 测试字符串参数回调
*/
testDoSthWithString: function () {
callWithStringParam(
this.stringParam,
function(response){
uni.showToast({
title:'uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:'+response,
icon:'none'
});
},
);
},
/**
* 测试json参数回调
*/
testDoSthWithJSON: function () {
var inputObject = {
inputText:this.stringParam,
errCode:0
}
callWithJSONParam({
input:inputObject,
success:function(response){
uni.showToast({
title:'执行结果:' + JSON.stringify(response),
icon:'none'
});
}
});
},
}
}
</script>
<style>
</style>
\ No newline at end of file
<template>
<view>
<page-head :title="title"></page-head>
<button @tap="testGoOtherActivity">跳转选择界面</button>
<image :src="selectImage" v-if="selectImage"></image>
<button @tap="testUnRegLifecycle">取消注册周期函数</button>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
</view>
<view class="uni-hello-text">
2. 手动切换其他APP再返回,可在控制台和界面观察事件日志
</view>
</view>
<view class="uni-padding-wrap uni-common-mt">
<view class="text-box" scroll-y="true">
<text>{{text}}</text>
</view>
</view>
</view>
</template>
<script>
import { initAppLifecycle,unRegLifecycle,goOtherActivity } from '../../uni_modules/uts-advance';
export default {
data() {
return {
title: '生命周期监听',
text: '',
selectImage:""
}
},
onLoad:function(){
let that = this;
initAppLifecycle(function(eventLog){
// 展示捕捉到的声明周期日志
that.text += eventLog;
that.text += '\n';
});
},
methods:{
testGoOtherActivity(){
var that = this;
let ret = goOtherActivity(function(file){
// 展示捕捉到的声明周期日志
console.log(file);
that.selectImage = "file://" + file;
});
if(!ret){
uni.showToast({
icon:'none',
title:'请授予权限后重试'
})
}
},
testUnRegLifecycle(){
// 取消注册生命周期
unRegLifecycle();
}
}
}
</script>
<style>
.text-box {
margin-bottom: 40rpx;
padding: 40rpx 0;
display: flex;
min-height: 300rpx;
background-color: #FFFFFF;
justify-content: center;
align-items: center;
text-align: center;
font-size: 30rpx;
color: #353535;
line-height: 1.8;
}
</style>
<template>
<view>
<page-head :title="title"></page-head>
<button @tap="testGoOtherActivity">跳转选择界面</button>
<image :src="selectImage" v-if="selectImage"></image>
<button @tap="testUnRegLifecycle">取消注册周期函数</button>
<view class="uni-padding-wrap uni-common-mt">
<view class="uni-hello-text">
1. 当前页面已通过initAppLifecycle函数注册了生命周期监听。
</view>
<view class="uni-hello-text">
2. 手动切换其他APP再返回,可在控制台和界面观察事件日志
</view>
</view>
<view class="uni-padding-wrap uni-common-mt">
<view class="text-box" scroll-y="true">
<text>{{text}}</text>
</view>
</view>
</view>
</template>
<script>
import { initAppLifecycle,unRegLifecycle,goOtherActivity } from '../../uni_modules/uts-advance';
export default {
data() {
return {
title: '生命周期监听',
text: '',
selectImage:""
}
},
onLoad:function(){
let that = this;
initAppLifecycle(function(eventLog){
// 展示捕捉到的声明周期日志
that.text = that.text += eventLog;
that.text = that.text += '\n';
});
},
methods:{
testGoOtherActivity(){
var that = this;
let ret = goOtherActivity(function(file){
// 展示捕捉到的声明周期日志
console.log(file);
that.selectImage = "file://" + file;
});
if(!ret){
uni.showToast({
icon:'none',
title:'请授予权限后重试'
})
}
},
testUnRegLifecycle(){
// 取消注册生命周期
unRegLifecycle();
}
}
}
</script>
<style>
.text-box {
margin-bottom: 40rpx;
padding: 40rpx 0;
display: flex;
min-height: 300rpx;
background-color: #FFFFFF;
justify-content: center;
align-items: center;
text-align: center;
font-size: 30rpx;
color: #353535;
line-height: 1.8;
}
</style>
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="getImageBase64">读取图片base64</button>
<button type="primary" @tap="getFileText">读取文本内容</button>
</view>
</view>
</template>
<script>
import { readFile,writeFile, ReadFileOptions, WriteFileOptions } from '../../uni_modules/uts-file-manager'
export default {
data() {
return {
title: '文件读取示例',
logo:""
}
},
methods: {
getImageBase64:function(){
readFile({
type:'base64',
path:'static/logo.png',
success:function(res){
console.log("success")
console.log(res)
},
fail:function(res){
console.log('fail')
console.log(res)
},
complete:function(res){
console.log("complete")
console.log(res)
}
} as ReadFileOptions)
},
getFileText:function(){
writeFile({
path:'/test/1.txt',
content:'锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦',
success:function(res){
readFile({
type:'text',
path:res.filePath,
success:function(res){
console.log("success")
console.log(res)
},
fail:function(res){
console.log('fail')
console.log(res)
},
complete:function(res){
console.log("complete")
console.log(res)
}
} as ReadFileOptions)
},
fail:function(res){
console.log('fail')
console.log(res)
},
complete:function(res){
console.log("complete")
console.log(res)
}
} as WriteFileOptions)
}
}
}
</script>
<style>
</style>
<template>
<view>
<page-head :title="title"></page-head>
<view class="uni-btn-v uni-common-mt">
<button type="primary" @tap="getImageBase64">读取图片base64</button>
<button type="primary" @tap="getFileText">读取文本内容</button>
</view>
</view>
</template>
<script>
import { readFile,writeFile } from '../../uni_modules/uts-file-manager'
export default {
data() {
return {
title: '文件读取示例',
logo:""
}
},
methods: {
getImageBase64:function(e){
readFile({
type:'base64',
path:'static/logo.png',
success:function(res){
console.log("success")
console.log(res)
},
fail:function(res){
console.log('fail')
console.log(res)
},
complete:function(res){
console.log("complete")
console.log(res)
}
})
},
getFileText:function(e){
writeFile({
path:'/test/1.txt',
content:'锄禾日当午,汗滴禾下土,谁知盘中餐,粒粒皆辛苦',
success:function(res){
readFile({
type:'text',
path:res.filePath,
success:function(res){
console.log("success")
console.log(res)
},
fail:function(res){
console.log('fail')
},
complete:function(res){
console.log("complete")
}
})
},
fail:function(res){
console.log('fail')
},
complete:function(res){
console.log("complete")
}
})
}
}
}
</script>
<style>
</style>
<template>
<view>
<page-head :title="title"></page-head>
<image :src="logo" mode="aspectFit" style="width: 100%;"></image>
</view>
</template>
<script>
import { getLogoPath } from '../../uni_modules/uts-advance'
export default {
data() {
return {
title: '资源加载示例',
logo:""
}
},
onLoad:function(){
this.logo = getLogoPath()
}
}
</script>
<style>
</style>
<template>
<view>
<page-head :title="title"></page-head>
<image :src="logo" mode="aspectFit" style="width: 100%;"></image>
</view>
</template>
<script>
import { getLogoPath } from '../../uni_modules/uts-advance'
export default {
data() {
return {
title: '资源加载示例',
logo:""
}
},
onLoad:function(){
this.logo = getLogoPath()
}
}
</script>
<style>
</style>
此差异已折叠。
此差异已折叠。
......@@ -181,3 +181,34 @@ export function callbackParam(callback : ParamCallback) {
}
callback(ret)
}
/**
* 打印测试方法
*/
export function logStrTest() {
console.log("logStrTest 字符串打印测试")
}
export function logFloatTest() {
console.log(3.1415926)
}
export function logIntTest() {
console.log(2023)
}
export function logObjectTest(){
let ret : ParamOptions = {
title: "logObjectTest",
array: ['1', '2', '3']
}
console.log(ret)
}
export function logFunctionTest(){
let testFun = function(){
console.log("testFun")
}
console.log(testFun)
}
{
"id": "uni-alert",
"displayName": "uni-alert",
"version": "1.0.0",
"description": "uni-alert",
"keywords": [
"uni-alert"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.11"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# uni-alert
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
\ No newline at end of file
import {
UTSAndroid
} from "io.dcloud.uts";
import Toast from 'android.widget.Toast';
import AlertDialog from 'android.app.AlertDialog';
import DialogInterface from 'android.content.DialogInterface';
import EditText from 'android.widget.EditText';
@Suppress("UNUSED_PARAMETER")
export function showAlert(_title : string | null, _message : string | null, _result : (index : Number) => void) {
let uiRunable = new DialogUIRunnable(null, _title!, _message!, "", false);
UTSAndroid.getUniActivity()!.runOnUiThread(uiRunable)
}
@Suppress("UNUSED_PARAMETER")
export function showPrompt(_title : string | null, _message : string | null, _placeholder : string | null, success : (content : string) => void) {
let uiRunable = new DialogUIRunnable(success, _title!, _message!, _placeholder!, true);
UTSAndroid.getUniActivity()!.runOnUiThread(uiRunable)
}
/**
* 用户输入对话框监听器
*/
class DialogListener extends DialogInterface.OnClickListener {
inputET : EditText
callback : (content : string) => void
constructor(et : EditText, cb : (content : string) => void) {
super();
this.callback = cb;
this.inputET = et;
}
override onClick(_dialog : DialogInterface, _arg1 : Int) : void {
//数据获取
let input = this.inputET.getText().toString()
this.callback(input);
Toast.makeText(UTSAndroid.getUniActivity(), input,
Toast.LENGTH_LONG).show();
}
}
/**
* Dialog ui任务封装
*/
class DialogUIRunnable extends Runnable {
callback ?: (content : string) => void = null
title : string
message : string
placeholder : string
needInput : boolean
constructor(success ?: (content : string) => void, title : string, message : string, placeholder : string, needInput : boolean) {
super();
if (success != null) {
this.callback = success
}
this.title = title
this.message = message
this.placeholder = placeholder
this.needInput = needInput
}
override run() : void {
if (this.needInput) {
let et = new EditText(UTSAndroid.getUniActivity());
et.setText(this.placeholder);
new AlertDialog.Builder(UTSAndroid.getUniActivity())
.setTitle(this.title)
.setMessage(this.message)
.setIcon(android.R.drawable.ic_dialog_info).setView(et)
.setPositiveButton("确定", new DialogListener(et, this.callback!))
.setNegativeButton("取消", null).show();
} else {
new AlertDialog.Builder(UTSAndroid.getUniActivity())
.setTitle(this.title)
.setMessage(this.message)
.setIcon(android.R.drawable.ic_dialog_info)
.setNegativeButton("取消", null).show();
}
}
};
\ No newline at end of file
import { UIAlertController , UIAlertAction , UITextField } from "UIKit"
import { UTSiOS } from "DCloudUTSFoundation"
import { DispatchQueue } from 'Dispatch';
export function showAlert(title: string|null, message: string|null, result: (index: Number) => void) {
// uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行
DispatchQueue.main.async(execute=():void => {
// 初始化 UIAlertController 实例对象 alert
let alert = new UIAlertController(title=title,message=message,preferredStyle=UIAlertController.Style.alert)
// 创建 UIAlertAction 按钮
let okAction = new UIAlertAction(title="确认", style=UIAlertAction.Style.default, handler=(action: UIAlertAction):void => {
// 点击按钮的回调方法
result(0)
})
// 创建 UIAlertAction 按钮
let cancelAction = new UIAlertAction(title="取消", style=UIAlertAction.Style.cancel, handler=(action: UIAlertAction):void => {
// 点击按钮的回调方法
result(1)
})
// 将 UIAlertAction 添加到 alert 上
alert.addAction(okAction)
alert.addAction(cancelAction)
// 打开 alert 弹窗
UTSiOS.getCurrentViewController().present(alert, animated= true)
})
}
export function showPrompt(title: string|null, message: string|null,placeholder: string|null, result: (content: string)=>void) {
// uts方法默认会在子线程中执行,涉及 UI 操作必须在主线程中运行,通过 DispatchQueue.main.async 方法可将代码在主线程中运行
DispatchQueue.main.async(execute=():void => {
// 初始化 UIAlertController 实例对象 alert
let alert = new UIAlertController(title=title,message=message,preferredStyle=UIAlertController.Style.alert)
// 在 alert 上添加输入框
alert.addTextField(configurationHandler=(tf: UITextField):void => {
// 添加成功的回调
// 设置输入框的 placeholder
tf.placeholder = placeholder
})
// 创建 UIAlertAction 按钮
let okAction = new UIAlertAction(title="确认", style=UIAlertAction.Style.default, handler=(action: UIAlertAction):void => {
// 点击按钮的回调方法
// 获取输入框中的内容
let tf = alert.textFields?.[0]
if (tf != null) {
result(tf!.text != null ? tf!.text! : "没有输入任何内容")
}
})
// 将 UIAlertAction 添加到 alert 上
alert.addAction(okAction)
// 打开 alert 弹窗
UTSiOS.getCurrentViewController().present(alert, animated= true)
})
}
\ No newline at end of file
{
"id": "uts-animation-view",
"displayName": "uts-animation-view",
"version": "1.0.0",
"description": "uts-animation-view",
"keywords": [
"animation-view","uts-animation-view","lottie"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# animation-view
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
\ No newline at end of file
{
"dependencies": [
"com.airbnb.android:lottie:3.4.0"
],
"minSdkVersion": 21
}
/**
* 判断当前的基座是否已经集成了sdk, 即是否是自定义基座
*/
export function checkHasLottieIntegration():boolean{
let hasIntegration = true
try{
let xClass = Class.forName("com.airbnb.lottie.LottieDrawable")
console.log(xClass);
}catch(e:Exception){
hasIntegration = false;
}
if(!hasIntegration){
return false;
}
return true
}
<template>
<view class="defaultStyles">
</view>
</template>
<script lang="uts">
import Animator from 'android.animation.Animator'
import TextUtils from 'android.text.TextUtils'
import View from 'android.view.View'
import LottieAnimationView from 'com.airbnb.lottie.LottieAnimationView'
import LottieDrawable from 'com.airbnb.lottie.LottieDrawable'
import FileInputStream from 'java.io.FileInputStream'
import { UTSAndroid } from "io.dcloud.uts";
class CustomAnimListener extends Animator.AnimatorListener {
comp: UTSComponent < LottieAnimationView >
constructor(com: UTSComponent < LottieAnimationView > ) {
super();
this.comp = com
}
override onAnimationStart(animation: Animator | null) {}
override onAnimationEnd(animation: Animator | null, isReverse: Boolean) {
this.comp.$emit("bindended")
}
override onAnimationEnd(animation: Animator | null) {}
override onAnimationCancel(animation: Animator | null) {}
override onAnimationRepeat(animation: Animator | null) {}
}
//原生提供以下属性或方法的实现
export default {
name: "uts-animation-view",
/**
* 当播放到末尾时触发 ended 事件(自然播放结束会触发回调,循环播放结束及手动停止动画不会触发)
*/
emits: ['bindended'],
props: {
/**
* 动画资源地址,目前只支持绝对路径
*/
"path": {
type: String,
default: ""
},
/**
* 动画是否自动播放
*/
"autoplay": {
type: Boolean,
default: false
},
/**
* 动画是否循环播放
*/
"loop": {
type: Boolean,
default: false
},
/**
* 是否隐藏动画
*/
"hidden": {
type: Boolean,
default: false
},
/**
* 动画操作,可取值 play、pause、stop
*/
"action": {
type: String,
default: "stop"
}
},
data() {
return {
}
},
watch: {
"path": {
handler(newPath: string) {
if(this.$el != null){
let lottieAnimationView = this.$el!
if (!TextUtils.isEmpty(newPath)) {
if (newPath.startsWith("http://") || newPath.startsWith("https://")) {
lottieAnimationView.setAnimationFromUrl(newPath)
} else {
// 默认是static了
var realJsonPath = UTSAndroid.getResourcePath(newPath)
lottieAnimationView.setAnimation(new FileInputStream(realJsonPath),newPath)
}
}
if (this.autoplay) {
lottieAnimationView.playAnimation()
}
}
},
immediate: false
},
"loop": {
handler(newLoop: Boolean) {
if(this.$el != null){
if (newLoop) {
this.$el!.repeatCount = Int.MAX_VALUE
} else {
// 不循环则设置成1次
this.$el!.repeatCount = 0
}
if (this.autoplay) {
this.$el!.playAnimation()
}
}
},
immediate: false
},
"autoplay": {
handler(newValue: boolean) {
if(this.$el != null){
if (newValue) {
this.$el!.playAnimation()
}
}
},
immediate: false
},
"action": {
handler(newAction: string) {
if (newAction == "play" || newAction == "pause" || newAction == "stop") {
if(this.$el != null){
if (this.action == "play") {
this.$el!.playAnimation()
} else if (this.action == "pause") {
this.$el!.pauseAnimation()
} else if (this.action == "stop") {
this.$el!.cancelAnimation()
this.$el!.clearAnimation()
}
}
} else {
// 非法入参,不管
}
},
immediate: false
},
"hidden": {
handler(newValue: boolean) {
if(this.$el != null){
if (newValue) {
this.$el!.visibility = View.GONE
} else {
this.$el!.visibility = View.VISIBLE
}
}
},
immediate: false
},
},
methods: {
setRepeatMode(repeat: string) {
if(this.$el != null){
if ("RESTART" == repeat) {
this.$el!.repeatMode = LottieDrawable.RESTART
} else if ("REVERSE" == repeat) {
this.$el!.repeatMode = LottieDrawable.RESTART
}
}
},
},
NVLoad(): LottieAnimationView {
let lottieAnimationView = new LottieAnimationView($androidContext)
return lottieAnimationView
},
NVLoaded() {
if(this.$el != null){
this.$el!.repeatMode = LottieDrawable.RESTART;
this.$el!.visibility = View.GONE
this.$el!.repeatCount = 0
this.$el!.addAnimatorListener(new CustomAnimListener(this))
}
}
}
</script>
<style>
/* 定义默认样式值, 组件使用者没有配置时使用 */
.defaultStyles {
width: 750rpx;
height: 240rpx;
}
</style>
{
"deploymentTarget": "11.0",
"validArchitectures": [
"arm64",
"x86_64"
]
}
/**
* 判断当前的基座是否已经集成了sdk, 即是否是自定义基座
*/
export function checkHasLottieIntegration():boolean{
return true
}
<template>
<view class="defaultStyles">
</view>
</template>
<script lang="uts">
import {
LottieAnimationView,
LottieAnimation,
LottieLoopMode
} from 'Lottie'
import {
URL
} from 'Foundation'
import {
UTSiOS
} from "DCloudUTSFoundation"
//原生提供以下属性或方法的实现
export default {
/**
* 组件名称,也就是开发者使用的标签
*/
name: "uts-animation-view",
/**
* 组件涉及的事件声明,只有声明过的事件,才能被正常发送
*/
emits: ['bindended'], // 当播放到末尾时触发 ended 事件(自然播放结束会触发回调,循环播放结束及手动停止动画不会触发)
/**
* 属性声明,组件的使用者会传递这些属性值到组件
*/
props: {
/**
* 动画资源地址,支持远程 URL 地址和本地绝对路径
*/
"path": {
type: String,
default: ""
},
/**
* 动画是否循环播放
*/
"autoplay": {
type: Boolean,
default: false
},
/**
* 动画是否自动播放
*/
"loop": {
type: Boolean,
default: false
},
/**
* 是否隐藏动画
*/
"hidden": {
type: Boolean,
default: false
},
/**
* 动画操作,可取值 play、pause、stop
*/
"action": {
type: String,
default: "stop"
}
},
data() {
return {
}
},
watch: {
"path": {
handler(newValue: string, oldValue: string) {
if (this.autoplay) {
this.playAnimation()
}
},
immediate: false //创建时是否通过此方法更新属性,默认值为false
},
"loop": {
handler(newValue: boolean, oldValue: boolean) {
if (newValue) {
this.$el.loopMode = LottieLoopMode.loop
} else {
this.$el.loopMode = LottieLoopMode.playOnce
}
},
immediate: false //创建时是否通过此方法更新属性,默认值为false
},
"autoplay": {
handler(newValue: boolean, oldValue: boolean) {
if (newValue) {
this.playAnimation()
}
},
immediate: false //创建时是否通过此方法更新属性,默认值为false
},
"action": {
handler(newValue: string, oldValue: string) {
const action = newValue
if (action == "play" || action == "pause" || action == "stop") {
switch (action) {
case "play":
this.playAnimation()
break;
case "pause":
this.$el.pause()
break;
case "stop":
this.$el.stop()
break;
default:
break;
}
} else {
// 非法入参,不管
}
},
immediate: false //创建时是否通过此方法更新属性,默认值为false
},
"hidden": {
handler(newValue: boolean, oldValue: boolean) {
this.$el.isHidden = this.hidden
},
immediate: false //创建时是否通过此方法更新属性,默认值为false
},
},
expose: ['setRepeatMode'],
methods: {
// 需要对外暴露的方法
// 设置 RepeatMode
setRepeatMode(repeatMode: string) {
if (repeatMode == "RESTART") {
if (this.loop) {
this.$el.loopMode = LottieLoopMode.loop
} else {
this.$el.loopMode = LottieLoopMode.playOnce
}
} else if (repeatMode == "REVERSE") {
if (this.loop) {
this.$el.loopMode = LottieLoopMode.autoReverse
} else {
this.$el.loopMode = LottieLoopMode.repeatBackwards(1)
}
}
},
// 不对外暴露的方法
// 播放动画
playAnimation() {
// 构建动画资源 url
var animationUrl: URL | null
if (this.path.hasPrefix("http")) {
animationUrl = new URL(string = this.path)
} else {
const filePath = UTSiOS.getResourcePath(this.path)
animationUrl = new URL(fileURLWithPath = filePath)
}
if (animationUrl != null) {
// 加载动画 LottieAnimation
LottieAnimation.loadedFrom(url = animationUrl!, closure = (animation: LottieAnimation | null):
void => {
if (animation != null) {
// 加载成功开始播放
this.$el.animation = animation
this.$el.play(completion = (isFinish: boolean): void => {
if (isFinish) {
// 播放完成回调事件
this.fireEvent("bindended")
}
})
}
})
} else {
console.log("url 构建失败,请检查 path 是否正确")
}
}
},
created() { //创建组件,替换created
},
NVBeforeLoad() { //组件将要创建,对应前端beforeMount
//可选实现,这里可以提前做一些操作
},
NVLoad(): LottieAnimationView { //创建原生View,必须定义返回值类型(Android需要明确知道View类型,需特殊校验)
// 初始化 Lottie$el
const animationView = new LottieAnimationView()
// 默认只播放一次动画
animationView.loopMode = LottieLoopMode.playOnce
return animationView
},
NVLoaded() { //原生View已创建
/// 更新 props 中定义的属性值
if (this.loop) {
this.$el.loopMode = LottieLoopMode.loop
}
this.$el.isHidden = this.hidden
if (this.autoplay) {
this.playAnimation()
}
},
NVLayouted() { //原生View布局完成
//可选实现,这里可以做布局后续操作
},
NVBeforeUnload() { //原生View将释放
//可选实现,这里可以做释放View之前的操作
},
NVUnloaded() { //原生View已释放
//可选实现,这里可以做释放View之后的操作
},
unmounted() { //组件销毁
//可选实现
}
}
</script>
<style>
//定义默认样式值, 组件使用者没有配置时使用
.defaultStyles {
width: 750rpx;
height: 240rpx;
}
</style>
\ No newline at end of file
{
"id": "uts-file-manager",
"displayName": "uts-file-manager",
"version": "1.0.0",
"description": "uts-file-manager",
"keywords": [
"uts-file-manager"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.8"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
},
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "u",
"aliyun": "u"
},
"client": {
"Vue": {
"vue2": "u",
"vue3": "u"
},
"App": {
"app-android": "u",
"app-ios": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
},
"快应用": {
"华为": "u",
"联盟": "u"
}
}
}
}
}
\ No newline at end of file
# uts-file-manager
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS API插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[UTS 组件插件](https://uniapp.dcloud.net.cn/plugin/uts-component.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts)
\ No newline at end of file
import { ReadFileSuccessResult, ReadFileFailResult, ReadFile,ReadFileOptions } from "../interface.uts"
import { WriteFileSuccessResult, WriteFileFailResult, WriteFile,WriteFileOptions } from "../interface.uts"
import File from "java.io.File"
import UTSAndroid from 'io.dcloud.uts.UTSAndroid';
import Base64 from "android.util.Base64"
import Environment from 'android.os.Environment';
export { ReadFileOptions, WriteFileOptions } from "../interface.uts"
/**
* 获取文件内容
*/
export const readFile : ReadFile = function (options : ReadFileOptions) {
// 判断type 是否合法
if(options.type != 'base64' && options.type != 'text'){
let ret : ReadFileFailResult = {
errCode: -1,
errMsg: "type error.",
errSubject: "uni-getFileContent"
}
options.fail?.(ret)
options.complete?.(ret)
return
}
/**
* 执行真正的加载行为,为了避免阻塞分发到 io任务序列
*/
UTSAndroid.dispatchAsync('io',function(_){
let filePath = UTSAndroid.convert2AbsFullPath(options.path)
let targetFile = new File(filePath)
if (!targetFile.exists()) {
let ret : ReadFileFailResult = {
errCode: -2,
errMsg: "file not found.",
errSubject: "uni-getFileContent"
}
options.fail?.(ret)
options.complete?.(ret)
return
}
if (targetFile.isDirectory()) {
let ret : ReadFileFailResult = {
errCode: -3,
errMsg: "error:file is a Directory.",
errSubject: "uni-getFileContent"
}
options.fail?.(ret)
options.complete?.(ret)
return
}
/**
* 文件超过16M,会超过应用内存
*/
if (targetFile.length() > 16 * 1024 * 1024) {
let ret : ReadFileFailResult = {
errCode: -3,
errMsg: "error:file is bigger than 16M",
errSubject: "uni-getFileContent"
}
options.fail?.(ret)
options.complete?.(ret)
return
}
if(options.type == 'base64'){
// base64
let byteArray = targetFile.readBytes()
let base64Content = Base64.encodeToString(byteArray,Base64.NO_WRAP)
let ret : ReadFileSuccessResult = {
content: base64Content,
}
options.success?.(ret)
options.complete?.(ret)
}else{
// text
let text = targetFile.readText()
let ret : ReadFileSuccessResult = {
content: text
}
options.success?.(ret)
options.complete?.(ret)
}
},null)
}
/**
* 获取文件内容
*/
export const writeFile : WriteFile = function (options : WriteFileOptions) {
// 判断type 是否合法
let nextFile = new File(UTSAndroid.getAppContext()?.getFilesDir(),options.path)
console.log(nextFile.getPath())
if(nextFile.exists() && nextFile.isDirectory()){
// 出错了,目标文件已存在,并且是个目录
let ret : WriteFileFailResult = {
errCode: -2,
errMsg: "file exist and is a directory.",
errSubject: "uni-writeFile"
}
options.fail?.(ret)
options.complete?.(ret)
return
}
UTSAndroid.dispatchAsync('io',function(_){
/**
* 如果上一级目录不存在,创建之
*/
if(!nextFile.parentFile.exists()){
nextFile.parentFile.mkdirs()
}
if(!nextFile.exists()){
nextFile.createNewFile()
}
// 写入文本,暂时只支持覆盖写入
nextFile.writeText(options.content)
let ret : WriteFileSuccessResult = {
filePath: nextFile.getPath()
}
options.success?.(ret)
options.complete?.(ret)
},null)
}
## 1.2.0(2022-10-17)
实现百度小程序/支付宝小程序/QQ小程序获取电量
## 1.1.0(2022-10-17)
实现ios平台获取电量
## 1.0.0(2022-09-01)
实现android/web/微信小程序平台获取电量
interface GetBatteryInfoSuccessCallbackResult {
/**
* 是否正在充电中
*/
isCharging: boolean;
/**
* 设备电量,范围 1 - 100
*/
level: number;
errMsg: string;
}
interface GetBatteryInfoOption {
/**
* 接口调用结束的回调函数(调用成功、失败都会执行)
*/
complete?: Function
/**
* 接口调用失败的回调函数
*/
fail?: Function
/**
* 接口调用成功的回调函数
*/
success?: (result: GetBatteryInfoSuccessCallbackResult) => void
}
declare class Uni {
/**
* 获取设备电量
*
* 文档: [https://uniapp.dcloud.net.cn/api/system/batteryInfo.html](https://uniapp.dcloud.net.cn/api/system/batteryInfo.html)
*/
getBatteryInfo(option?: GetBatteryInfoOption): void;
}
此差异已折叠。
# uts-getbatteryinfo
## 使用文档
```ts
import getBatteryInfo from "@/uni_modules/uts-getbatteryinfo";
// 获取电量信息
getBatteryInfo({
success(res) {
uni.showToast({
title: "当前电量:" + res.level + '%',
icon: 'none'
});
}
})
```
### 参数
Object object
|属性|类型|必填|说明|
|----|---|----|----|
|success|function|否|接口调用成功的回调函数|
|fail|function|否|接口调用失败的回调函数|
|complete|function|否|接口调用结束的回调函数(调用成功、失败都会执行)|
object.success 回调函数
|属性|类型|说明|
|----|---|----|
|level|number|设备电量,范围 1 - 100|
|isCharging|boolean|是否正在充电中|
{
"minSdkVersion": "21"
}
\ No newline at end of file
export default function getBatteryInfo(options) {
return my.getBatteryInfo(options)
}
export default function getBatteryInfo(options) {
return swan.getBatteryInfo(options)
}
export default function getBatteryInfo(options) {
return qq.getBatteryInfo(options)
}
export default function getBatteryInfo(options) {
return wx.getBatteryInfo(options)
}
此差异已折叠。
# uts-hello-component
### 开发文档
[UTS 语法](https://uniapp.dcloud.net.cn/tutorial/syntax-uts.html)
[UTS 原生插件](https://uniapp.dcloud.net.cn/plugin/uts-plugin.html)
[Hello UTS](https://gitcode.net/dcloud/hello-uts/-/tree/dev)
\ No newline at end of file
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册