提交 1685eb3a 编写于 作者: 杜庆泉's avatar 杜庆泉

lifecycle add

上级 1c4d58e0
......@@ -37,15 +37,6 @@
"enablePullDownRefresh": false
}
},
{
"path" : "pages/static/static",
"style" :
{
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path" : "pages/lifecycle/lifecycle",
......
<template>
<view>当前电量:</view>
<view>
<page-head :title="title"></page-head>
<view class="uni-padding-wrap uni-common-mt">
<view class="text-box" scroll-y="true">
<text>{{text}}</text>
</view>
</view>
</view>
</template>
<script lang="ts" setup>
import { initAppLifecycle } from '../../uni_modules/uts-advance'
initAppLifecycle();
<script>
import { initAppLifecycle } from '../../uni_modules/uts-advance';
export default {
data() {
return {
title: '生命周期监听',
text: '',
}
},
onLoad:function(){
let that = this;
initAppLifecycle(function(name){
that.text = that.text += name;
that.text = that.text += '\n';
});
}
}
</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>
......@@ -3,15 +3,14 @@
<page-head :title="title"></page-head>
<image :src="logo" mode="aspectFit" style="width: 100%;"></image>
<view class="uni-btn-v uni-common-mt">
<button type="primary" >展示插件内置图片</button>
<button type="primary" @tap="testLogoLoad">展示插件内置图片</button>
<button type="primary" @tap="testAssetLoad" >播放asset音频(需自定义基座)</button>
<button type="primary" @tap="testResText" >获取res目录资源(需自定义基座)</button>
</view>
</view>
</template>
<script>
import { getLogoPath,playAssetAudio,getResText } from '../../uni_modules/uts-advance'
import { getLogoPath,playAssetAudio } from '../../uni_modules/uts-advance'
export default {
......@@ -28,11 +27,9 @@
testAssetLoad(){
playAssetAudio();
},
testResText(){
let resText = getResText();
console.log(resText);
testLogoLoad(){
this.logo = getLogoPath()
}
}
}
</script>
......
<template>
<view>
<view></view>
</view>
<image :src="logo"></image>
</template>
<script lang="ts" setup>
import { getLogoPath } from '../../uni_modules/uts-advance'
const logo = getLogoPath()
</script>
\ No newline at end of file
# uts-advance
UTS进阶示例插件
\ No newline at end of file
......@@ -10,13 +10,18 @@ import Runnable from 'java.lang.Runnable';
import Exception from 'java.lang.Exception';
import MediaPlayer from 'android.media.MediaPlayer';
/**
* 定时任务参数封装
*/
type TimerOptions = {
start: (res: string) => void;
work: (res: string) => void;
};
/**
* 执行延时任务
*/
export function doTimerTask(opts:TimerOptions) {
opts.start('doTimerTask start');
setTimeout(function() {
......@@ -26,7 +31,9 @@ export function doTimerTask(opts:TimerOptions) {
return { name: "doTimerTask" };
}
/**
* 执行周期任务
*/
export function doIntervalTask(opts:TimerOptions) {
let taskRet = setInterval(function() {
......@@ -37,6 +44,9 @@ export function doIntervalTask(opts:TimerOptions) {
return { name: "doIntervalTask",taskId:taskRet};
}
/**
* 清除周期任务
*/
export function clearIntervalTask(taskId:number) {
clearInterval(taskId);
......@@ -85,14 +95,12 @@ class RemoveUIRunnable extends Runnable {
export function addViewToDecorView() {
let uiRunable = new AddUIRunnable();
// 获取android环境下 宿主decorview的基本信息
getUniActivity()!.runOnUiThread(uiRunable)
}
export function removeViewToDecorView() {
var uiRunable = new RemoveUIRunnable();
// 获取android环境下 宿主decorview的基本信息
getUniActivity()!.runOnUiThread(uiRunable)
}
......@@ -124,31 +132,32 @@ export function playAssetAudio() {
}
const RTEXT:number = 10020;
export function getResText() :string{
// let text = "aaa " + com.sina.weibo.sdk.R2.string.com_sina_weibo_sdk_logout;
// let resText = getAppContext()!.getString(io.dcloud.uni_modules.uts_advance.R.string.dcloud_common_app_res_download_failed)
return "222";
}
export function initAppLifecycle() {
console.log("initAppLifecycle");
export function initAppLifecycle(onLifecycleChange: (event:string) => void) {
onAppActivityDestroy(() => {
console.log("onAppActivityDestroy");
let eventName = "onAppActivityDestroy - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
});
onAppActivityPause(() => {
console.log("onAppActivityPause");
let eventName = "onAppActivityPause - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
});
onAppActivityResume(() => {
console.log("onAppActivityResume");
let eventName = "onAppActivityResume - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
});
onAppActivityBack(() => {
console.log("onAppActivityBack");
let eventName = "onAppActivityBack - " + Date.now();
onLifecycleChange(eventName);
console.log(eventName);
});
}
......
<resources>
<string name="uts_resource_text">Chinese Text</string>
</resources>
\ No newline at end of file
<resources>
<string name="uts_resource_text">English Text</string>
</resources>
\ No newline at end of file
# uts-helloworld
UTS入门示例插件
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册