提交 7dca62c8 编写于 作者: 杜庆泉's avatar 杜庆泉

add uts doc

上级 21bfe6e7
...@@ -37,15 +37,15 @@ ...@@ -37,15 +37,15 @@
}); });
}, },
testDoSthWithString: function () { testDoSthWithString: function () {
callWithStringParam({ callWithStringParam(
input:this.stringParam, this.stringParam,
success:function(response){ function(response){
uni.showToast({ uni.showToast({
title:'uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:'+response, title:'uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:'+response,
icon:'none' icon:'none'
}); });
}, },
}); );
}, },
testDoSthWithJSON: function () { testDoSthWithJSON: function () {
console.log(this.jsonParam); console.log(this.jsonParam);
......
...@@ -36,9 +36,12 @@ export function callWithoutParam(opts: NoParamOptions) { ...@@ -36,9 +36,12 @@ export function callWithoutParam(opts: NoParamOptions) {
return { name: "doSthWithCallback" }; return { name: "doSthWithCallback" };
} }
export function callWithStringParam(opts: StringParamOptions) {
export function callWithStringParam(input:string,success: (res: string) => void) {
setTimeout(function() { setTimeout(function() {
opts.success(opts.input); success(input);
}, 500); }, 500);
return { name: "doSthWithCallback" }; return { name: "doSthWithCallback" };
......
var __defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,a)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,__spreadValues=(e,t)=>{for(var a in t||(t={}))__hasOwnProp.call(t,a)&&__defNormalProp(e,a,t[a]);if(__getOwnPropSymbols)for(var a of __getOwnPropSymbols(t))__propIsEnum.call(t,a)&&__defNormalProp(e,a,t[a]);return e};if("undefined"==typeof Promise||Promise.prototype.finally||(Promise.prototype.finally=function(e){const t=this.constructor;return this.then((a=>t.resolve(e()).then((()=>a))),(a=>t.resolve(e()).then((()=>{throw a}))))}),"undefined"!=typeof uni&&uni&&uni.requireGlobal){const e=uni.requireGlobal();ArrayBuffer=e.ArrayBuffer,Int8Array=e.Int8Array,Uint8Array=e.Uint8Array,Uint8ClampedArray=e.Uint8ClampedArray,Int16Array=e.Int16Array,Uint16Array=e.Uint16Array,Int32Array=e.Int32Array,Uint32Array=e.Uint32Array,Float32Array=e.Float32Array,Float64Array=e.Float64Array,BigInt64Array=e.BigInt64Array,BigUint64Array=e.BigUint64Array}uni.restoreGlobal&&uni.restoreGlobal(Vue,weex,plus,setTimeout,clearTimeout,setInterval,clearInterval),function(e,t){"use strict";function a(t,a){return"Function"===e.toRawType(a)?"function() { [native code] }":a}function n(t,n,c){if("string"==typeof __channelId__&&__channelId__)return c.push(n.replace("at ","uni-app:///")),console[t].apply(console,c);return c.map((function(t){const n=e.toTypeString(t).toLowerCase();if(-1!==["[object object]","[object array]","[object module]"].indexOf(n))try{t="---BEGIN:JSON---"+JSON.stringify(t,a)+"---END:JSON---"}catch(c){t=n}else if(null===t)t="---NULL---";else if(void 0===t)t="---UNDEFINED---";else{const a=e.toRawType(t).toUpperCase();t="NUMBER"===a||"BOOLEAN"===a?"---BEGIN:"+a+"---"+t+"---END:"+a+"---":String(t)}return t})).join("---COMMA---")+" "+n}function c(e,t,...a){const c=n(e,t,a);c&&console[e](c)}var l=(e,t)=>{const a=e.__vccOpts||e;for(const[n,c]of t)a[n]=c;return a};var s=l({name:"page-head",props:{title:{type:String,default:""}}},[["render",function(e,a,n,c,l,s){return t.openBlock(),t.createElementBlock("view",{class:"common-page-head"},[t.createElementVNode("view",{class:"common-page-head-title"},t.toDisplayString(n.title),1)])}]]);function r(t,a){return e.isString(t)?a:t}let o,i=1;const u={};function p(t){if("function"==typeof t){const e=i++;return u[e]=t,e}return e.isPlainObject(t)&&Object.keys(t).forEach((e=>{t[e]=p(t[e])})),t}function m(){var e;return o||(e="UTS-Proxy",o=weex.requireModule(e)),o}function d(e){if(e.errMsg)throw new Error(e.errMsg);return e.params}function y(e){return d(m().invokeSync(e,(()=>{})))}function v(t,{package:a,class:n,name:c,id:l,companion:s}){const r=({id:e,name:t,params:l,keepAlive:s})=>{const r=u[e];r?(r(...l),s||delete u[e]):console.error(`${a}${n}.${c} ${t} is not found`)},o=l?{id:l,name:c}:{package:a,class:n,name:c,companion:s};return(...a)=>{const n=e.extend({},o,{params:a.map((e=>p(e)))});return t?new Promise(((e,t)=>{m().invokeAsync(n,(a=>{"return"!==a.type?r(a):a.errMsg?t(a.errMsg):e(a.params)}))})):d(m().invokeSync(n,r))}}function g(e,t){return v(e,t)}const b=g;const f="uts.modules.utsHelloworld",A="IndexKt",h=b(!1,{package:f,class:A,name:"callWithoutParam"}),S=b(!1,{package:f,class:A,name:"callWithStringParam"}),k=b(!1,{package:f,class:A,name:"callWithJSONParam"});var w=l({data:()=>({title:"UTS入门示例",stringParam:"hello world"}),onUnload:function(){},methods:{testDoSthWithCallback:function(){h({success:function(){uni.showToast({title:"成功调用uts插件uts-helloworld的callWithoutParam",icon:"none"})}})},testDoSthWithString:function(){S({input:this.stringParam,success:function(e){uni.showToast({title:"uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:"+e,icon:"none"})}})},testDoSthWithJSON:function(){c("log","at pages/tabBar/Primer/Primer.vue:51",this.jsonParam);var e={inputText:this.stringParam};k({input:e,success:function(e){c("log","at pages/tabBar/Primer/Primer.vue:59",e),uni.showToast({title:"执行结果:"+JSON.stringify(e),icon:"none"})}})}}},[["render",function(e,a,n,c,l,o){const i=r(t.resolveDynamicComponent("page-head"),s);return t.openBlock(),t.createElementBlock("view",null,[t.createVNode(i,{title:l.title},null,8,["title"]),t.withDirectives(t.createElementVNode("input",{class:"uni-input","onUpdate:modelValue":a[0]||(a[0]=e=>l.stringParam=e)},null,512),[[t.vModelText,l.stringParam]]),t.createElementVNode("view",{class:"uni-btn-v uni-common-mt"},[t.createElementVNode("button",{type:"primary",onClick:a[1]||(a[1]=(...e)=>o.testDoSthWithCallback&&o.testDoSthWithCallback(...e))},"uts异步方法(无参数)"),t.createElementVNode("button",{type:"primary",onClick:a[2]||(a[2]=(...e)=>o.testDoSthWithString&&o.testDoSthWithString(...e))},"uts异步方法(字符串参数)"),t.createElementVNode("button",{type:"primary",onClick:a[3]||(a[3]=(...e)=>o.testDoSthWithJSON&&o.testDoSthWithJSON(...e))},"uts异步方法(json参数)")])])}]]);const N="uts.modules.utsAdvance",E="IndexKt",C=b(!1,{package:N,class:E,name:"testSync"}),_=b(!1,{package:N,class:E,name:"testSyncWithCallback"}),V=b(!0,{package:N,class:E,name:"testAsync"}),B=function({package:t,class:a,methods:n,props:c,staticProps:l,staticMethods:s}){const r={package:t,class:a},o={};return new Proxy(class{constructor(...t){const a={},l=v(!1,e.extend({name:"constructor",params:t},r)).apply(null,t);return new Proxy(this,{get(t,s){if(!a[s])if(e.hasOwn(n,s))a[s]=(o=!!n[s].async,i=e.extend({id:l,name:s},r),v(o,i));else if(c.includes(s))return y({id:l,name:s});var o,i;return a[s]}})}},{get:(t,a,n)=>e.hasOwn(s,a)?(o[a]||(o[a]=g(!!s[a].async,e.extend({name:a,companion:!0},r))),o[a]):l.includes(a)?y(e.extend({name:a,companion:!0},r)):Reflect.get(t,a,n)})}(__spreadValues({package:N,class:"Test"},{methods:{testClassSyncWithCallback:{async:!1},testClassAsync:{async:!0}},staticMethods:{testClassStaticSyncWithCallback:{async:!1},testClassStaticAsync:{async:!0}},props:["id","name"],staticProps:["type"]})),P=t.defineComponent({__name:"Advance",setup(e){c("log","at pages/tabBar/Advance/Advance.vue:54","MAX",100);const a=t.ref(null),n=t.reactive({return:null,success:null,fail:null,complete:null}),l=t.reactive({return:null,success:null,fail:null,complete:null});function s(){r(),o(),i(),y(),g(),f(),h(),k(),N(),P()}function r(){a.value=!1;try{"hello dcloud"===C("dcloud").msg&&(a.value=!0)}catch(e){c("error","at pages/tabBar/Advance/Advance.vue:93","testUtsSync",e)}}function o(){try{n.return=!1,n.success=!1,n.complete=!1,"testSyncWithCallback"===_({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:106","testSyncWithCallback.success.callback",e),n.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:110","testSyncWithCallback.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:114","testSyncWithCallback.complete.callback",e),n.complete=!0}}).name&&(n.return=!0)}catch(e){}}async function i(){l.return=!1,l.success=!1,l.complete=!1;try{"testAsync"===(await V({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:132","testAsync.success.callback",e),l.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:136","testAsync.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:139","testAsync.complete.callback",e),l.complete=!0}})).name&&(l.return=!0)}catch(e){}}function u(e){return null==e?"--":e?"通过":"未通过"}let p,m=0;const d=t.reactive({callback:null});function y(){d.callback=!1,m++,p=new B(m,{name:"name"+m,callback:e=>{c("log","at pages/tabBar/Advance/Advance.vue:161",e),d.callback=!0}})}const v=t.ref(null);function g(){v.value=!1,"Test"===B.type&&(v.value=!0)}const b=t.reactive({return:null,success:null,fail:null,complete:null});function f(){try{b.return=!1,b.success=!1,b.complete=!1,"testSyncWithCallback"===B.testClassStaticSyncWithCallback({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:189","testStaticSyncWithCallback.success.callback",e),b.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:193","testStaticSyncWithCallback.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:197","testStaticSyncWithCallback.complete.callback",e),b.complete=!0}}).name&&(b.return=!0)}catch(e){}}const A=t.reactive({return:null,success:null,fail:null,complete:null});async function h(){A.return=!1,A.success=!1,A.complete=!1;try{"testAsync"===(await B.testClassStaticAsync({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:221","testAsync.success.callback",e),A.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:225","testAsync.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:228","testAsync.complete.callback",e),A.complete=!0}})).name&&(A.return=!0)}catch(e){}}const S=t.ref(null);function k(){p||y(),S.value=!1,p.id>0&&(S.value=!0)}const w=t.reactive({return:null,success:null,fail:null,complete:null});function N(){p||y();try{w.return=!1,w.success=!1,w.complete=!1,"testSyncWithCallback"===p.testClassSyncWithCallback({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:268","testSyncWithCallback.success.callback",e),w.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:272","testSyncWithCallback.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:276","testSyncWithCallback.complete.callback",e),w.complete=!0}}).name&&(w.return=!0)}catch(e){}}const E=t.reactive({return:null,success:null,fail:null,complete:null});async function P(){p||y(),E.return=!1,E.success=!1,E.complete=!1;try{"testAsync"===(await p.testClassAsync({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:303","testAsync.success.callback",e),E.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:307","testAsync.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:310","testAsync.complete.callback",e),E.complete=!0}})).name&&(E.return=!0)}catch(e){}}return(e,c)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.createElementVNode("button",{onClick:r},"点击测试uts同步方法"),t.createElementVNode("view",null,"测试return: "+t.toDisplayString(u(a.value)),1),t.createElementVNode("button",{onClick:o}," 点击测试uts带callback的同步方法 "),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(n.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(n.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(n.complete)),1),t.createElementVNode("button",{onClick:i},"点击测试uts异步方法"),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(l.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(l.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(l.complete)),1),t.createElementVNode("button",{onClick:y},"点击测试uts class构造函数"),t.createElementVNode("view",null,"测试callback:"+t.toDisplayString(u(d.callback)),1),t.createElementVNode("button",{onClick:g},"点击测试uts class静态属性"),t.createElementVNode("view",null,"测试value:"+t.toDisplayString(u(v.value)),1),t.createElementVNode("button",{onClick:f}," 点击测试uts class静态方法 "),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(b.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(b.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(b.complete)),1),t.createElementVNode("button",{onClick:h},"点击测试uts class静态异步方法"),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(A.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(A.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(A.complete)),1),t.createElementVNode("button",{onClick:k},"点击测试uts class实例属性"),t.createElementVNode("view",null,"测试value:"+t.toDisplayString(u(S.value)),1),t.createElementVNode("button",{onClick:N}," 点击测试uts class实例方法 "),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(w.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(w.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(w.complete)),1),t.createElementVNode("button",{onClick:P},"点击测试uts class实例异步方法"),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(E.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(E.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(E.complete)),1),t.createElementVNode("button",{onClick:s},"点击测试所有")],64))}}),D=b(!1,{package:"uts.modules.utsOsapi",class:"IndexKt",name:"getBatteryCapacity"});var W=l({data:()=>({title:"系统API示例"}),onUnload:function(){},methods:{testGetBatteryCapacity:function(){c("log","at pages/tabBar/SystemAPI/SystemAPI.vue:25",D()),uni.showToast({title:"122",icon:"none"})}}},[["render",function(e,a,n,c,l,o){const i=r(t.resolveDynamicComponent("page-head"),s);return t.openBlock(),t.createElementBlock("view",null,[t.createVNode(i,{title:l.title},null,8,["title"]),t.createElementVNode("view",{class:"uni-btn-v uni-common-mt"},[t.createElementVNode("button",{type:"primary",onClick:a[0]||(a[0]=(...e)=>o.testGetBatteryCapacity&&o.testGetBatteryCapacity(...e))},"获取电池电量")])])}]]);var O=l({data:()=>({}),methods:{}},[["render",function(e,a,n,c,l,s){return t.openBlock(),t.createElementBlock("view",null,[t.createElementVNode("text",null,"sdk集成")])}]]);__definePage("pages/tabBar/Primer/Primer",w),__definePage("pages/tabBar/Advance/Advance",P),__definePage("pages/tabBar/SystemAPI/SystemAPI",W),__definePage("pages/tabBar/SDKIntegration/SDKIntegration",O);const I={onLaunch:function(){c("log","at App.vue:4","App Launch")},onShow:function(){c("log","at App.vue:7","App Show")},onHide:function(){c("log","at App.vue:10","App Hide")}};const{app:U,Vuex:x,Pinia:T}={app:t.createVueApp(I)};uni.Vuex=x,uni.Pinia=T,U.provide("__globalStyles",__uniConfig.styles),U._component.mpType="app",U._component.render=()=>{},U.mount("#app")}(uni.VueShared,Vue); if("undefined"==typeof Promise||Promise.prototype.finally||(Promise.prototype.finally=function(t){const e=this.constructor;return this.then((n=>e.resolve(t()).then((()=>n))),(n=>e.resolve(t()).then((()=>{throw n}))))}),"undefined"!=typeof uni&&uni&&uni.requireGlobal){const t=uni.requireGlobal();ArrayBuffer=t.ArrayBuffer,Int8Array=t.Int8Array,Uint8Array=t.Uint8Array,Uint8ClampedArray=t.Uint8ClampedArray,Int16Array=t.Int16Array,Uint16Array=t.Uint16Array,Int32Array=t.Int32Array,Uint32Array=t.Uint32Array,Float32Array=t.Float32Array,Float64Array=t.Float64Array,BigInt64Array=t.BigInt64Array,BigUint64Array=t.BigUint64Array}uni.restoreGlobal&&uni.restoreGlobal(Vue,weex,plus,setTimeout,clearTimeout,setInterval,clearInterval),function(t,e){"use strict";function n(e,n){return"Function"===t.toRawType(n)?"function() { [native code] }":n}function a(e,a,o){if("string"==typeof __channelId__&&__channelId__)return o.push(a.replace("at ","uni-app:///")),console[e].apply(console,o);return o.map((function(e){const a=t.toTypeString(e).toLowerCase();if(-1!==["[object object]","[object array]","[object module]"].indexOf(a))try{e="---BEGIN:JSON---"+JSON.stringify(e,n)+"---END:JSON---"}catch(o){e=a}else if(null===e)e="---NULL---";else if(void 0===e)e="---UNDEFINED---";else{const n=t.toRawType(e).toUpperCase();e="NUMBER"===n||"BOOLEAN"===n?"---BEGIN:"+n+"---"+e+"---END:"+n+"---":String(e)}return e})).join("---COMMA---")+" "+a}function o(t,e,...n){const o=a(t,e,n);o&&console[t](o)}var r=(t,e)=>{const n=t.__vccOpts||t;for(const[a,o]of e)n[a]=o;return n};var i=r({name:"page-head",props:{title:{type:String,default:""}}},[["render",function(t,n,a,o,r,i){return e.openBlock(),e.createElementBlock("view",{class:"common-page-head"},[e.createElementVNode("view",{class:"common-page-head-title"},e.toDisplayString(a.title),1)])}]]);function l(e,n){return t.isString(e)?n:e}let s,c=1;const u={};function p(e){if("function"==typeof e){const t=c++;return u[t]=e,t}return t.isPlainObject(e)&&Object.keys(e).forEach((t=>{e[t]=p(e[t])})),e}function m(){var t;return s||(t="UTS-Proxy",s=weex.requireModule(t)),s}function d(e,{package:n,class:a,name:o,id:r,companion:i}){const l=({id:t,name:e,params:r,keepAlive:i})=>{const l=u[t];l?(l(...r),i||delete u[t]):console.error(`${n}${a}.${o} ${e} is not found`)},s=r?{id:r,name:o}:{package:n,class:a,name:o,companion:i};return(...n)=>{const a=t.extend({},s,{params:n.map((t=>p(t)))});return e?new Promise(((t,e)=>{m().invokeAsync(a,(n=>{"return"!==n.type?l(n):n.errMsg?e(n.errMsg):t(n.params)}))})):function(t){if(t.errMsg)throw new Error(t.errMsg);return t.params}(m().invokeSync(a,l))}}const y=function(t,e){return d(t,e)},f="uts.modules.utsHelloworld",h="IndexKt",g=y(!1,{package:f,class:h,name:"callWithoutParam"}),v=y(!1,{package:f,class:h,name:"callWithStringParam"}),A=y(!1,{package:f,class:h,name:"callWithJSONParam"});var k=r({data:()=>({title:"UTS入门示例",stringParam:"hello world"}),onUnload:function(){},methods:{testDoSthWithCallback:function(){g({success:function(){uni.showToast({title:"成功调用uts插件uts-helloworld的callWithoutParam",icon:"none"})}})},testDoSthWithString:function(){v(this.stringParam,(function(t){uni.showToast({title:"uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:"+t,icon:"none"})}))},testDoSthWithJSON:function(){o("log","at pages/tabBar/Primer/Primer.vue:51",this.jsonParam);var t={inputText:this.stringParam};A({input:t,success:function(t){o("log","at pages/tabBar/Primer/Primer.vue:59",t),uni.showToast({title:"执行结果:"+JSON.stringify(t),icon:"none"})}})}}},[["render",function(t,n,a,o,r,s){const c=l(e.resolveDynamicComponent("page-head"),i);return e.openBlock(),e.createElementBlock("view",null,[e.createVNode(c,{title:r.title},null,8,["title"]),e.withDirectives(e.createElementVNode("input",{class:"uni-input","onUpdate:modelValue":n[0]||(n[0]=t=>r.stringParam=t)},null,512),[[e.vModelText,r.stringParam]]),e.createElementVNode("view",{class:"uni-btn-v uni-common-mt"},[e.createElementVNode("button",{type:"primary",onClick:n[1]||(n[1]=(...t)=>s.testDoSthWithCallback&&s.testDoSthWithCallback(...t))},"uts异步方法(无参数)"),e.createElementVNode("button",{type:"primary",onClick:n[2]||(n[2]=(...t)=>s.testDoSthWithString&&s.testDoSthWithString(...t))},"uts异步方法(字符串参数)"),e.createElementVNode("button",{type:"primary",onClick:n[3]||(n[3]=(...t)=>s.testDoSthWithJSON&&s.testDoSthWithJSON(...t))},"uts异步方法(json参数)")])])}]]);const S="uts.modules.utsAdvance",I="IndexKt",w=y(!1,{package:S,class:I,name:"doTimerTask"}),P=y(!1,{package:S,class:I,name:"doIntervalTask"});var N=r({data:()=>({title:"UTS进阶示例",taskId:0}),onUnload:function(){},methods:{testTimer:function(){w({start:function(t){uni.showToast({title:t,icon:"none"})},work:function(t){uni.showToast({title:t,icon:"none"})}})},testInterval:function(){var t=P({start:function(t){uni.showToast({title:t,icon:"none"})},work:function(t){uni.showToast({title:t,icon:"none"})}});this.taskId=t.taskId},testClearInterval:function(){o("log","at pages/tabBar/Advance/Advance.vue:62",this.taskId)}}},[["render",function(t,n,a,o,r,s){const c=l(e.resolveDynamicComponent("page-head"),i);return e.openBlock(),e.createElementBlock("view",null,[e.createVNode(c,{title:r.title},null,8,["title"]),e.createElementVNode("view",{class:"uni-btn-v uni-common-mt"},[e.createElementVNode("button",{type:"primary",onClick:n[0]||(n[0]=(...t)=>s.testTimer&&s.testTimer(...t))},"延迟任务"),e.createElementVNode("button",{type:"primary",onClick:n[1]||(n[1]=(...t)=>s.testInterval&&s.testInterval(...t))},"定时任务"),e.createElementVNode("button",{type:"primary",onClick:n[2]||(n[2]=(...t)=>s.testClearInterval&&s.testClearInterval(...t))},"关闭定时任务")])])}]]);const b=y(!1,{package:"uts.modules.utsOsapi",class:"IndexKt",name:"getBatteryCapacity"});var B=r({data:()=>({title:"系统API示例"}),onUnload:function(){},methods:{testGetBatteryCapacity:function(){var t=b();o("log","at pages/tabBar/SystemAPI/SystemAPI.vue:25",t),uni.showToast({title:"当前电量:"+t,icon:"none"})}}},[["render",function(t,n,a,o,r,s){const c=l(e.resolveDynamicComponent("page-head"),i);return e.openBlock(),e.createElementBlock("view",null,[e.createVNode(c,{title:r.title},null,8,["title"]),e.createElementVNode("view",{class:"uni-btn-v uni-common-mt"},[e.createElementVNode("button",{type:"primary",onClick:n[0]||(n[0]=(...t)=>s.testGetBatteryCapacity&&s.testGetBatteryCapacity(...t))},"获取电池电量")])])}]]);var E=r({data:()=>({}),methods:{}},[["render",function(t,n,a,o,r,i){return e.openBlock(),e.createElementBlock("view",null,[e.createElementVNode("text",null,"sdk集成")])}]]);__definePage("pages/tabBar/Primer/Primer",k),__definePage("pages/tabBar/Advance/Advance",N),__definePage("pages/tabBar/SystemAPI/SystemAPI",B),__definePage("pages/tabBar/SDKIntegration/SDKIntegration",E);const C={onLaunch:function(){o("log","at App.vue:4","App Launch")},onShow:function(){o("log","at App.vue:7","App Show")},onHide:function(){o("log","at App.vue:10","App Hide")}};const{app:T,Vuex:_,Pinia:V}={app:e.createVueApp(C)};uni.Vuex=_,uni.Pinia=V,T.provide("__globalStyles",__uniConfig.styles),T._component.mpType="app",T._component.render=()=>{},T.mount("#app")}(uni.VueShared,Vue);
...@@ -4,70 +4,28 @@ import kotlinx.coroutines.CoroutineScope; ...@@ -4,70 +4,28 @@ import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.Deferred; import kotlinx.coroutines.Deferred;
import kotlinx.coroutines.Dispatchers; import kotlinx.coroutines.Dispatchers;
import io.dcloud.uts.*; import io.dcloud.uts.*;
fun log(msg: String) { open class TimerOptions {
console.log(msg, "at uni_modules/uts-advance/app-android/utils.uts:2"); open lateinit var start: UTSCallback;
} open lateinit var work: UTSCallback;
open class AsyncOptions { }
open lateinit var type: String; fun doTimerTask(opts: TimerOptions): UtsJSONObject {
open lateinit var success: UTSCallback; opts.start("doTimerTask start");
open lateinit var fail: UTSCallback; setTimeout(fun() {
open lateinit var complete: UTSCallback; opts.work("doTimerTask work");
} }
val MAX = 100; , 2000);
fun testSync(msg: String): UtsJSONObject {
console.log("log test", "at uni_modules/uts-advance/app-android/index.uts:18");
log("log test1");
return object : UtsJSONObject() { return object : UtsJSONObject() {
var msg = """hello ${msg}""" var name = "doTimerTask"
}; };
} }
fun testSyncError() { fun doIntervalTask(opts: TimerOptions): UtsJSONObject {
val arr: MutableList<String> = mutableListOf(); var taskRet = setInterval(fun() {
console.log(arr[1], "at uni_modules/uts-advance/app-android/index.uts:29"); opts.work("doIntervalTask work");
} }
fun testSyncWithCallback(opts: AsyncOptions): UtsJSONObject { , 2000);
if (opts.type == "success") opts.success("success"); opts.start("doIntervalTask start");
else opts.fail("fail");
opts.complete("complete");
return object : UtsJSONObject() { return object : UtsJSONObject() {
var name = "testSyncWithCallback" var name = "doIntervalTask"
}; var taskId = taskRet
}
suspend fun testAsync(opts: AsyncOptions): Deferred<UtsJSONObject> = CoroutineScope(Dispatchers.Default).async {
if (opts.type == "success") opts.success("success");
else opts.fail("fail");
opts.complete("complete");
return@async object : UtsJSONObject() {
var name = "testAsync"
}; };
} }
open class TestOptions {
open lateinit var name: String;
open lateinit var callback: UTSCallback;
}
open class Test {
open var id: Number;
open var name: String;
constructor(id: Number, options: TestOptions){
this.id = id;
this.name = options.name;
options.callback("Test.constructor");
}
open fun testClassSyncWithCallback(opts: AsyncOptions): UtsJSONObject {
return testSyncWithCallback(opts);
}
open suspend fun testClassAsync(opts: AsyncOptions): Deferred<UtsJSONObject> = CoroutineScope(Dispatchers.Default).async {
val res = testAsync(opts).await();
return@async res;
}
companion object {
var type: String = "Test";
fun testClassStaticSyncWithCallback(opts: AsyncOptions): UtsJSONObject {
return testSyncWithCallback(opts);
}
suspend fun testClassStaticAsync(opts: AsyncOptions): Deferred<UtsJSONObject> = CoroutineScope(Dispatchers.Default).async {
val res = testAsync(opts).await();
return@async res;
}
}
}
...@@ -34,9 +34,9 @@ fun callWithoutParam(opts: NoParamOptions): UtsJSONObject { ...@@ -34,9 +34,9 @@ fun callWithoutParam(opts: NoParamOptions): UtsJSONObject {
var name = "doSthWithCallback" var name = "doSthWithCallback"
}; };
} }
fun callWithStringParam(opts: StringParamOptions): UtsJSONObject { fun callWithStringParam(input: String, success: (res: String) -> Unit): UtsJSONObject {
setTimeout(fun() { setTimeout(fun() {
opts.success(opts.input); success(input);
} }
, 500); , 500);
return object : UtsJSONObject() { return object : UtsJSONObject() {
......
...@@ -12,7 +12,7 @@ fun getBatteryCapacity(): String { ...@@ -12,7 +12,7 @@ fun getBatteryCapacity(): String {
if (context != null) { if (context != null) {
val manager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager; val manager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager;
val currentLevel: Number = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); val currentLevel: Number = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
return "" + currentLevel + "**456464%"; return "" + currentLevel + "%";
} }
return "0%"; return "0%";
} }
...@@ -199,14 +199,11 @@ if (uni.restoreGlobal) { ...@@ -199,14 +199,11 @@ if (uni.restoreGlobal) {
}); });
}, },
testDoSthWithString: function() { testDoSthWithString: function() {
callWithStringParam({ callWithStringParam(this.stringParam, function(response) {
input: this.stringParam,
success: function(response) {
uni.showToast({ uni.showToast({
title: "uts\u63D2\u4EF6uts-helloworld\u7684callWithStringParam\u65B9\u6CD5\u6536\u5230\u4E86\u4F60\u8F93\u5165\u7684\u5B57\u7B26\u4E32\uFF1A" + response, title: "uts\u63D2\u4EF6uts-helloworld\u7684callWithStringParam\u65B9\u6CD5\u6536\u5230\u4E86\u4F60\u8F93\u5165\u7684\u5B57\u7B26\u4E32\uFF1A" + response,
icon: "none" icon: "none"
}); });
}
}); });
}, },
testDoSthWithJSON: function() { testDoSthWithJSON: function() {
......
...@@ -34,9 +34,9 @@ fun callWithoutParam(opts: NoParamOptions): UtsJSONObject { ...@@ -34,9 +34,9 @@ fun callWithoutParam(opts: NoParamOptions): UtsJSONObject {
var name = "doSthWithCallback" var name = "doSthWithCallback"
}; };
} }
fun callWithStringParam(opts: StringParamOptions): UtsJSONObject { fun callWithStringParam(input: String, success: (res: String) -> Unit): UtsJSONObject {
setTimeout(fun() { setTimeout(fun() {
opts.success(opts.input); success(input);
} }
, 500); , 500);
return object : UtsJSONObject() { return object : UtsJSONObject() {
......
{"version":3,"sources":["\\\\?\\D:\\Do\\Source\\hello-uts\\uni_modules\\uts-helloworld\\app-android\\index.uts"],"sourcesContent":["type NoParamOptions = {\n success: (res: string) => void;\n fail: (res: string) => void;\n complete: (res: string) => void;\n};\r\n\r\ntype StringParamOptions = {\r\n input:string;\n success: (res: string) => void;\n fail: (res: string) => void;\n complete: (res: string) => void;\n};\r\n\r\n\r\ntype inputJSON = {\r\n\tinputText:string,\r\n\terrCode:number\r\n}\r\ntype JsonParamOptions = {\r\n input:inputJSON;\n success: (res: string) => void;\n fail: (res: string) => void;\n complete: (res: string) => void;\n};\r\n\r\n\r\n/**\n * 导出一个带callback的同步方法\n * @param opts\n */\nexport function callWithoutParam(opts: NoParamOptions) {\r\n\tsetTimeout(function() {\r\n\t\topts.success();\r\n\t}, 500);\n \n return { name: \"doSthWithCallback\" };\n}\r\n\r\nexport function callWithStringParam(opts: StringParamOptions) {\r\n\tsetTimeout(function() {\r\n\t\topts.success(opts.input);\r\n\t}, 500);\n \n return { name: \"doSthWithCallback\" };\n}\r\n\r\n\r\nexport function callWithJSONParam(opts: JsonParamOptions) {\r\n\topts.input.errCode = 10;\r\n\tsetTimeout(function() {\r\n\t\topts.success(opts.input);\r\n\t}, 500);\n \n return { name: \"doSthWithCallback\" };\n}\r\n\r\n\r\n"],"names":[],"mappings":";;;;;;AAAsB,WAAjB,cAAc;IACjB,kBAAA,OAAO,EAAA,WAAuB,CAAC;IAC/B,kBAAA,IAAI,EAAA,WAAuB,CAAC;IAC5B,kBAAA,QAAQ,EAAA,WAAuB,CAAC;CACjC,AAAC;AAEwB,WAArB,kBAAkB;IACrB,kBAAA,KAAK,EAAC,MAAM,CAAC;IACb,kBAAA,OAAO,EAAA,WAAuB,CAAC;IAC/B,kBAAA,IAAI,EAAA,WAAuB,CAAC;IAC5B,kBAAA,QAAQ,EAAA,WAAuB,CAAC;CACjC,AAAC;AAGe,WAAZ,SAAS;IACb,kBAAA,SAAS,EAAC,MAAM,CAAC;IACjB,kBAAA,OAAO,EAAC,MAAM,CAAA;CACd;AACuB,WAAnB,gBAAgB;IACnB,kBAAA,KAAK,EAAC,SAAS,CAAC;IAChB,kBAAA,OAAO,EAAA,WAAuB,CAAC;IAC/B,kBAAA,IAAI,EAAA,WAAuB,CAAC;IAC5B,kBAAA,QAAQ,EAAA,WAAuB,CAAC;CACjC,AAAC;AAOK,IAAS,gBAAgB,CAAC,IAAoB,EAAd,cAAc,iBAAE;IACtD,UAAU,CAAC,MAAW;QACrB,IAAI,CAAC,OAAO,EAAE,CAAC;;IACf,EAAE,GAAG,CAAC,CAAC;IAEP,OAAO;QAAE,IAAA,IAAI,GAAE,mBAAmB;KAAE,CAAC;;AAGhC,IAAS,mBAAmB,CAAC,IAAwB,EAAlB,kBAAkB,iBAAE;IAC7D,UAAU,CAAC,MAAW;QACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;;IACzB,EAAE,GAAG,CAAC,CAAC;IAEP,OAAO;QAAE,IAAA,IAAI,GAAE,mBAAmB;KAAE,CAAC;;AAIhC,IAAS,iBAAiB,CAAC,IAAsB,EAAhB,gBAAgB,iBAAE;IACzD,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;IACxB,UAAU,CAAC,MAAW;QACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;;IACzB,EAAE,GAAG,CAAC,CAAC;IAEP,OAAO;QAAE,IAAA,IAAI,GAAE,mBAAmB;KAAE,CAAC"} {"version":3,"sources":["\\\\?\\D:\\Do\\Source\\hello-uts\\uni_modules\\uts-helloworld\\app-android\\index.uts"],"sourcesContent":["type NoParamOptions = {\n success: (res: string) => void;\n fail: (res: string) => void;\n complete: (res: string) => void;\n};\r\n\r\ntype StringParamOptions = {\r\n input:string;\n success: (res: string) => void;\n fail: (res: string) => void;\n complete: (res: string) => void;\n};\r\n\r\n\r\ntype inputJSON = {\r\n\tinputText:string,\r\n\terrCode:number\r\n}\r\ntype JsonParamOptions = {\r\n input:inputJSON;\n success: (res: string) => void;\n fail: (res: string) => void;\n complete: (res: string) => void;\n};\r\n\r\n\r\n/**\n * 导出一个带callback的同步方法\n * @param opts\n */\nexport function callWithoutParam(opts: NoParamOptions) {\r\n\tsetTimeout(function() {\r\n\t\topts.success();\r\n\t}, 500);\n \n return { name: \"doSthWithCallback\" };\n}\r\n\r\n\n \r\nexport function callWithStringParam(input:string,success: (res: string) => void) {\r\n\t\r\n\tsetTimeout(function() {\r\n\t\tsuccess(input);\r\n\t}, 500);\n \n return { name: \"doSthWithCallback\" };\n}\r\n\r\n\r\nexport function callWithJSONParam(opts: JsonParamOptions) {\r\n\topts.input.errCode = 10;\r\n\tsetTimeout(function() {\r\n\t\topts.success(opts.input);\r\n\t}, 500);\n \n return { name: \"doSthWithCallback\" };\n}\r\n\r\n\r\n"],"names":[],"mappings":";;;;;;AAAsB,WAAjB,cAAc;IACjB,kBAAA,OAAO,EAAA,WAAuB,CAAC;IAC/B,kBAAA,IAAI,EAAA,WAAuB,CAAC;IAC5B,kBAAA,QAAQ,EAAA,WAAuB,CAAC;CACjC,AAAC;AAEwB,WAArB,kBAAkB;IACrB,kBAAA,KAAK,EAAC,MAAM,CAAC;IACb,kBAAA,OAAO,EAAA,WAAuB,CAAC;IAC/B,kBAAA,IAAI,EAAA,WAAuB,CAAC;IAC5B,kBAAA,QAAQ,EAAA,WAAuB,CAAC;CACjC,AAAC;AAGe,WAAZ,SAAS;IACb,kBAAA,SAAS,EAAC,MAAM,CAAC;IACjB,kBAAA,OAAO,EAAC,MAAM,CAAA;CACd;AACuB,WAAnB,gBAAgB;IACnB,kBAAA,KAAK,EAAC,SAAS,CAAC;IAChB,kBAAA,OAAO,EAAA,WAAuB,CAAC;IAC/B,kBAAA,IAAI,EAAA,WAAuB,CAAC;IAC5B,kBAAA,QAAQ,EAAA,WAAuB,CAAC;CACjC,AAAC;AAOK,IAAS,gBAAgB,CAAC,IAAoB,EAAd,cAAc,iBAAE;IACtD,UAAU,CAAC,MAAW;QACrB,IAAI,CAAC,OAAO,EAAE,CAAC;;IACf,EAAE,GAAG,CAAC,CAAC;IAEP,OAAO;QAAE,IAAA,IAAI,GAAE,mBAAmB;KAAE,CAAC;;AAKhC,IAAS,mBAAmB,CAAC,KAAY,EAAN,MAAM,EAAC,OAA8B,GAApB,GAAW,EAAN,MAAM,KAAK,IAAI,iBAAE;IAEhF,UAAU,CAAC,MAAW;QACrB,OAAO,CAAC,KAAK,CAAC,CAAC;;IACf,EAAE,GAAG,CAAC,CAAC;IAEP,OAAO;QAAE,IAAA,IAAI,GAAE,mBAAmB;KAAE,CAAC;;AAIhC,IAAS,iBAAiB,CAAC,IAAsB,EAAhB,gBAAgB,iBAAE;IACzD,IAAI,CAAC,KAAK,CAAC,OAAO,GAAG,EAAE,CAAC;IACxB,UAAU,CAAC,MAAW;QACrB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;;IACzB,EAAE,GAAG,CAAC,CAAC;IAEP,OAAO;QAAE,IAAA,IAAI,GAAE,mBAAmB;KAAE,CAAC"}
\ No newline at end of file \ No newline at end of file
var __defProp=Object.defineProperty,__getOwnPropSymbols=Object.getOwnPropertySymbols,__hasOwnProp=Object.prototype.hasOwnProperty,__propIsEnum=Object.prototype.propertyIsEnumerable,__defNormalProp=(e,t,a)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:a}):e[t]=a,__spreadValues=(e,t)=>{for(var a in t||(t={}))__hasOwnProp.call(t,a)&&__defNormalProp(e,a,t[a]);if(__getOwnPropSymbols)for(var a of __getOwnPropSymbols(t))__propIsEnum.call(t,a)&&__defNormalProp(e,a,t[a]);return e};if("undefined"==typeof Promise||Promise.prototype.finally||(Promise.prototype.finally=function(e){const t=this.constructor;return this.then((a=>t.resolve(e()).then((()=>a))),(a=>t.resolve(e()).then((()=>{throw a}))))}),"undefined"!=typeof uni&&uni&&uni.requireGlobal){const e=uni.requireGlobal();ArrayBuffer=e.ArrayBuffer,Int8Array=e.Int8Array,Uint8Array=e.Uint8Array,Uint8ClampedArray=e.Uint8ClampedArray,Int16Array=e.Int16Array,Uint16Array=e.Uint16Array,Int32Array=e.Int32Array,Uint32Array=e.Uint32Array,Float32Array=e.Float32Array,Float64Array=e.Float64Array,BigInt64Array=e.BigInt64Array,BigUint64Array=e.BigUint64Array}uni.restoreGlobal&&uni.restoreGlobal(Vue,weex,plus,setTimeout,clearTimeout,setInterval,clearInterval),function(e,t){"use strict";function a(t,a){return"Function"===e.toRawType(a)?"function() { [native code] }":a}function n(t,n,c){if("string"==typeof __channelId__&&__channelId__)return c.push(n.replace("at ","uni-app:///")),console[t].apply(console,c);return c.map((function(t){const n=e.toTypeString(t).toLowerCase();if(-1!==["[object object]","[object array]","[object module]"].indexOf(n))try{t="---BEGIN:JSON---"+JSON.stringify(t,a)+"---END:JSON---"}catch(c){t=n}else if(null===t)t="---NULL---";else if(void 0===t)t="---UNDEFINED---";else{const a=e.toRawType(t).toUpperCase();t="NUMBER"===a||"BOOLEAN"===a?"---BEGIN:"+a+"---"+t+"---END:"+a+"---":String(t)}return t})).join("---COMMA---")+" "+n}function c(e,t,...a){const c=n(e,t,a);c&&console[e](c)}var l=(e,t)=>{const a=e.__vccOpts||e;for(const[n,c]of t)a[n]=c;return a};var s=l({name:"page-head",props:{title:{type:String,default:""}}},[["render",function(e,a,n,c,l,s){return t.openBlock(),t.createElementBlock("view",{class:"common-page-head"},[t.createElementVNode("view",{class:"common-page-head-title"},t.toDisplayString(n.title),1)])}]]);function r(t,a){return e.isString(t)?a:t}let o,i=1;const u={};function p(t){if("function"==typeof t){const e=i++;return u[e]=t,e}return e.isPlainObject(t)&&Object.keys(t).forEach((e=>{t[e]=p(t[e])})),t}function m(){var e;return o||(e="UTS-Proxy",o=weex.requireModule(e)),o}function d(e){if(e.errMsg)throw new Error(e.errMsg);return e.params}function y(e){return d(m().invokeSync(e,(()=>{})))}function v(t,{package:a,class:n,name:c,id:l,companion:s}){const r=({id:e,name:t,params:l,keepAlive:s})=>{const r=u[e];r?(r(...l),s||delete u[e]):console.error(`${a}${n}.${c} ${t} is not found`)},o=l?{id:l,name:c}:{package:a,class:n,name:c,companion:s};return(...a)=>{const n=e.extend({},o,{params:a.map((e=>p(e)))});return t?new Promise(((e,t)=>{m().invokeAsync(n,(a=>{"return"!==a.type?r(a):a.errMsg?t(a.errMsg):e(a.params)}))})):d(m().invokeSync(n,r))}}function g(e,t){return v(e,t)}const b=g;const f="uts.modules.utsHelloworld",A="IndexKt",h=b(!1,{package:f,class:A,name:"callWithoutParam"}),S=b(!1,{package:f,class:A,name:"callWithStringParam"}),k=b(!1,{package:f,class:A,name:"callWithJSONParam"});var w=l({data:()=>({title:"UTS入门示例",stringParam:"hello world"}),onUnload:function(){},methods:{testDoSthWithCallback:function(){h({success:function(){uni.showToast({title:"成功调用uts插件uts-helloworld的callWithoutParam",icon:"none"})}})},testDoSthWithString:function(){S({input:this.stringParam,success:function(e){uni.showToast({title:"uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:"+e,icon:"none"})}})},testDoSthWithJSON:function(){c("log","at pages/tabBar/Primer/Primer.vue:51",this.jsonParam);var e={inputText:this.stringParam};k({input:e,success:function(e){c("log","at pages/tabBar/Primer/Primer.vue:59",e),uni.showToast({title:"执行结果:"+JSON.stringify(e),icon:"none"})}})}}},[["render",function(e,a,n,c,l,o){const i=r(t.resolveDynamicComponent("page-head"),s);return t.openBlock(),t.createElementBlock("view",null,[t.createVNode(i,{title:l.title},null,8,["title"]),t.withDirectives(t.createElementVNode("input",{class:"uni-input","onUpdate:modelValue":a[0]||(a[0]=e=>l.stringParam=e)},null,512),[[t.vModelText,l.stringParam]]),t.createElementVNode("view",{class:"uni-btn-v uni-common-mt"},[t.createElementVNode("button",{type:"primary",onClick:a[1]||(a[1]=(...e)=>o.testDoSthWithCallback&&o.testDoSthWithCallback(...e))},"uts异步方法(无参数)"),t.createElementVNode("button",{type:"primary",onClick:a[2]||(a[2]=(...e)=>o.testDoSthWithString&&o.testDoSthWithString(...e))},"uts异步方法(字符串参数)"),t.createElementVNode("button",{type:"primary",onClick:a[3]||(a[3]=(...e)=>o.testDoSthWithJSON&&o.testDoSthWithJSON(...e))},"uts异步方法(json参数)")])])}]]);const N="uts.modules.utsAdvance",E="IndexKt",C=b(!1,{package:N,class:E,name:"testSync"}),_=b(!1,{package:N,class:E,name:"testSyncWithCallback"}),V=b(!0,{package:N,class:E,name:"testAsync"}),B=function({package:t,class:a,methods:n,props:c,staticProps:l,staticMethods:s}){const r={package:t,class:a},o={};return new Proxy(class{constructor(...t){const a={},l=v(!1,e.extend({name:"constructor",params:t},r)).apply(null,t);return new Proxy(this,{get(t,s){if(!a[s])if(e.hasOwn(n,s))a[s]=(o=!!n[s].async,i=e.extend({id:l,name:s},r),v(o,i));else if(c.includes(s))return y({id:l,name:s});var o,i;return a[s]}})}},{get:(t,a,n)=>e.hasOwn(s,a)?(o[a]||(o[a]=g(!!s[a].async,e.extend({name:a,companion:!0},r))),o[a]):l.includes(a)?y(e.extend({name:a,companion:!0},r)):Reflect.get(t,a,n)})}(__spreadValues({package:N,class:"Test"},{methods:{testClassSyncWithCallback:{async:!1},testClassAsync:{async:!0}},staticMethods:{testClassStaticSyncWithCallback:{async:!1},testClassStaticAsync:{async:!0}},props:["id","name"],staticProps:["type"]})),P=t.defineComponent({__name:"Advance",setup(e){c("log","at pages/tabBar/Advance/Advance.vue:54","MAX",100);const a=t.ref(null),n=t.reactive({return:null,success:null,fail:null,complete:null}),l=t.reactive({return:null,success:null,fail:null,complete:null});function s(){r(),o(),i(),y(),g(),f(),h(),k(),N(),P()}function r(){a.value=!1;try{"hello dcloud"===C("dcloud").msg&&(a.value=!0)}catch(e){c("error","at pages/tabBar/Advance/Advance.vue:93","testUtsSync",e)}}function o(){try{n.return=!1,n.success=!1,n.complete=!1,"testSyncWithCallback"===_({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:106","testSyncWithCallback.success.callback",e),n.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:110","testSyncWithCallback.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:114","testSyncWithCallback.complete.callback",e),n.complete=!0}}).name&&(n.return=!0)}catch(e){}}async function i(){l.return=!1,l.success=!1,l.complete=!1;try{"testAsync"===(await V({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:132","testAsync.success.callback",e),l.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:136","testAsync.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:139","testAsync.complete.callback",e),l.complete=!0}})).name&&(l.return=!0)}catch(e){}}function u(e){return null==e?"--":e?"通过":"未通过"}let p,m=0;const d=t.reactive({callback:null});function y(){d.callback=!1,m++,p=new B(m,{name:"name"+m,callback:e=>{c("log","at pages/tabBar/Advance/Advance.vue:161",e),d.callback=!0}})}const v=t.ref(null);function g(){v.value=!1,"Test"===B.type&&(v.value=!0)}const b=t.reactive({return:null,success:null,fail:null,complete:null});function f(){try{b.return=!1,b.success=!1,b.complete=!1,"testSyncWithCallback"===B.testClassStaticSyncWithCallback({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:189","testStaticSyncWithCallback.success.callback",e),b.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:193","testStaticSyncWithCallback.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:197","testStaticSyncWithCallback.complete.callback",e),b.complete=!0}}).name&&(b.return=!0)}catch(e){}}const A=t.reactive({return:null,success:null,fail:null,complete:null});async function h(){A.return=!1,A.success=!1,A.complete=!1;try{"testAsync"===(await B.testClassStaticAsync({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:221","testAsync.success.callback",e),A.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:225","testAsync.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:228","testAsync.complete.callback",e),A.complete=!0}})).name&&(A.return=!0)}catch(e){}}const S=t.ref(null);function k(){p||y(),S.value=!1,p.id>0&&(S.value=!0)}const w=t.reactive({return:null,success:null,fail:null,complete:null});function N(){p||y();try{w.return=!1,w.success=!1,w.complete=!1,"testSyncWithCallback"===p.testClassSyncWithCallback({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:268","testSyncWithCallback.success.callback",e),w.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:272","testSyncWithCallback.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:276","testSyncWithCallback.complete.callback",e),w.complete=!0}}).name&&(w.return=!0)}catch(e){}}const E=t.reactive({return:null,success:null,fail:null,complete:null});async function P(){p||y(),E.return=!1,E.success=!1,E.complete=!1;try{"testAsync"===(await p.testClassAsync({type:"success",success(e){c("log","at pages/tabBar/Advance/Advance.vue:303","testAsync.success.callback",e),E.success=!0},fail(e){c("log","at pages/tabBar/Advance/Advance.vue:307","testAsync.fail.callback",e)},complete(e){c("log","at pages/tabBar/Advance/Advance.vue:310","testAsync.complete.callback",e),E.complete=!0}})).name&&(E.return=!0)}catch(e){}}return(e,c)=>(t.openBlock(),t.createElementBlock(t.Fragment,null,[t.createElementVNode("button",{onClick:r},"点击测试uts同步方法"),t.createElementVNode("view",null,"测试return: "+t.toDisplayString(u(a.value)),1),t.createElementVNode("button",{onClick:o}," 点击测试uts带callback的同步方法 "),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(n.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(n.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(n.complete)),1),t.createElementVNode("button",{onClick:i},"点击测试uts异步方法"),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(l.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(l.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(l.complete)),1),t.createElementVNode("button",{onClick:y},"点击测试uts class构造函数"),t.createElementVNode("view",null,"测试callback:"+t.toDisplayString(u(d.callback)),1),t.createElementVNode("button",{onClick:g},"点击测试uts class静态属性"),t.createElementVNode("view",null,"测试value:"+t.toDisplayString(u(v.value)),1),t.createElementVNode("button",{onClick:f}," 点击测试uts class静态方法 "),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(b.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(b.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(b.complete)),1),t.createElementVNode("button",{onClick:h},"点击测试uts class静态异步方法"),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(A.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(A.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(A.complete)),1),t.createElementVNode("button",{onClick:k},"点击测试uts class实例属性"),t.createElementVNode("view",null,"测试value:"+t.toDisplayString(u(S.value)),1),t.createElementVNode("button",{onClick:N}," 点击测试uts class实例方法 "),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(w.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(w.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(w.complete)),1),t.createElementVNode("button",{onClick:P},"点击测试uts class实例异步方法"),t.createElementVNode("view",null,"测试return:"+t.toDisplayString(u(E.return)),1),t.createElementVNode("view",null,"测试success:"+t.toDisplayString(u(E.success)),1),t.createElementVNode("view",null,"测试complete:"+t.toDisplayString(u(E.complete)),1),t.createElementVNode("button",{onClick:s},"点击测试所有")],64))}}),D=b(!1,{package:"uts.modules.utsOsapi",class:"IndexKt",name:"getBatteryCapacity"});var W=l({data:()=>({title:"系统API示例"}),onUnload:function(){},methods:{testGetBatteryCapacity:function(){c("log","at pages/tabBar/SystemAPI/SystemAPI.vue:25",D()),uni.showToast({title:"122",icon:"none"})}}},[["render",function(e,a,n,c,l,o){const i=r(t.resolveDynamicComponent("page-head"),s);return t.openBlock(),t.createElementBlock("view",null,[t.createVNode(i,{title:l.title},null,8,["title"]),t.createElementVNode("view",{class:"uni-btn-v uni-common-mt"},[t.createElementVNode("button",{type:"primary",onClick:a[0]||(a[0]=(...e)=>o.testGetBatteryCapacity&&o.testGetBatteryCapacity(...e))},"获取电池电量")])])}]]);var O=l({data:()=>({}),methods:{}},[["render",function(e,a,n,c,l,s){return t.openBlock(),t.createElementBlock("view",null,[t.createElementVNode("text",null,"sdk集成")])}]]);__definePage("pages/tabBar/Primer/Primer",w),__definePage("pages/tabBar/Advance/Advance",P),__definePage("pages/tabBar/SystemAPI/SystemAPI",W),__definePage("pages/tabBar/SDKIntegration/SDKIntegration",O);const I={onLaunch:function(){c("log","at App.vue:4","App Launch")},onShow:function(){c("log","at App.vue:7","App Show")},onHide:function(){c("log","at App.vue:10","App Hide")}};const{app:U,Vuex:x,Pinia:T}={app:t.createVueApp(I)};uni.Vuex=x,uni.Pinia=T,U.provide("__globalStyles",__uniConfig.styles),U._component.mpType="app",U._component.render=()=>{},U.mount("#app")}(uni.VueShared,Vue); if("undefined"==typeof Promise||Promise.prototype.finally||(Promise.prototype.finally=function(t){const e=this.constructor;return this.then((n=>e.resolve(t()).then((()=>n))),(n=>e.resolve(t()).then((()=>{throw n}))))}),"undefined"!=typeof uni&&uni&&uni.requireGlobal){const t=uni.requireGlobal();ArrayBuffer=t.ArrayBuffer,Int8Array=t.Int8Array,Uint8Array=t.Uint8Array,Uint8ClampedArray=t.Uint8ClampedArray,Int16Array=t.Int16Array,Uint16Array=t.Uint16Array,Int32Array=t.Int32Array,Uint32Array=t.Uint32Array,Float32Array=t.Float32Array,Float64Array=t.Float64Array,BigInt64Array=t.BigInt64Array,BigUint64Array=t.BigUint64Array}uni.restoreGlobal&&uni.restoreGlobal(Vue,weex,plus,setTimeout,clearTimeout,setInterval,clearInterval),function(t,e){"use strict";function n(e,n){return"Function"===t.toRawType(n)?"function() { [native code] }":n}function a(e,a,o){if("string"==typeof __channelId__&&__channelId__)return o.push(a.replace("at ","uni-app:///")),console[e].apply(console,o);return o.map((function(e){const a=t.toTypeString(e).toLowerCase();if(-1!==["[object object]","[object array]","[object module]"].indexOf(a))try{e="---BEGIN:JSON---"+JSON.stringify(e,n)+"---END:JSON---"}catch(o){e=a}else if(null===e)e="---NULL---";else if(void 0===e)e="---UNDEFINED---";else{const n=t.toRawType(e).toUpperCase();e="NUMBER"===n||"BOOLEAN"===n?"---BEGIN:"+n+"---"+e+"---END:"+n+"---":String(e)}return e})).join("---COMMA---")+" "+a}function o(t,e,...n){const o=a(t,e,n);o&&console[t](o)}var r=(t,e)=>{const n=t.__vccOpts||t;for(const[a,o]of e)n[a]=o;return n};var i=r({name:"page-head",props:{title:{type:String,default:""}}},[["render",function(t,n,a,o,r,i){return e.openBlock(),e.createElementBlock("view",{class:"common-page-head"},[e.createElementVNode("view",{class:"common-page-head-title"},e.toDisplayString(a.title),1)])}]]);function l(e,n){return t.isString(e)?n:e}let s,c=1;const u={};function p(e){if("function"==typeof e){const t=c++;return u[t]=e,t}return t.isPlainObject(e)&&Object.keys(e).forEach((t=>{e[t]=p(e[t])})),e}function m(){var t;return s||(t="UTS-Proxy",s=weex.requireModule(t)),s}function d(e,{package:n,class:a,name:o,id:r,companion:i}){const l=({id:t,name:e,params:r,keepAlive:i})=>{const l=u[t];l?(l(...r),i||delete u[t]):console.error(`${n}${a}.${o} ${e} is not found`)},s=r?{id:r,name:o}:{package:n,class:a,name:o,companion:i};return(...n)=>{const a=t.extend({},s,{params:n.map((t=>p(t)))});return e?new Promise(((t,e)=>{m().invokeAsync(a,(n=>{"return"!==n.type?l(n):n.errMsg?e(n.errMsg):t(n.params)}))})):function(t){if(t.errMsg)throw new Error(t.errMsg);return t.params}(m().invokeSync(a,l))}}const y=function(t,e){return d(t,e)},f="uts.modules.utsHelloworld",h="IndexKt",g=y(!1,{package:f,class:h,name:"callWithoutParam"}),v=y(!1,{package:f,class:h,name:"callWithStringParam"}),A=y(!1,{package:f,class:h,name:"callWithJSONParam"});var k=r({data:()=>({title:"UTS入门示例",stringParam:"hello world"}),onUnload:function(){},methods:{testDoSthWithCallback:function(){g({success:function(){uni.showToast({title:"成功调用uts插件uts-helloworld的callWithoutParam",icon:"none"})}})},testDoSthWithString:function(){v(this.stringParam,(function(t){uni.showToast({title:"uts插件uts-helloworld的callWithStringParam方法收到了你输入的字符串:"+t,icon:"none"})}))},testDoSthWithJSON:function(){o("log","at pages/tabBar/Primer/Primer.vue:51",this.jsonParam);var t={inputText:this.stringParam};A({input:t,success:function(t){o("log","at pages/tabBar/Primer/Primer.vue:59",t),uni.showToast({title:"执行结果:"+JSON.stringify(t),icon:"none"})}})}}},[["render",function(t,n,a,o,r,s){const c=l(e.resolveDynamicComponent("page-head"),i);return e.openBlock(),e.createElementBlock("view",null,[e.createVNode(c,{title:r.title},null,8,["title"]),e.withDirectives(e.createElementVNode("input",{class:"uni-input","onUpdate:modelValue":n[0]||(n[0]=t=>r.stringParam=t)},null,512),[[e.vModelText,r.stringParam]]),e.createElementVNode("view",{class:"uni-btn-v uni-common-mt"},[e.createElementVNode("button",{type:"primary",onClick:n[1]||(n[1]=(...t)=>s.testDoSthWithCallback&&s.testDoSthWithCallback(...t))},"uts异步方法(无参数)"),e.createElementVNode("button",{type:"primary",onClick:n[2]||(n[2]=(...t)=>s.testDoSthWithString&&s.testDoSthWithString(...t))},"uts异步方法(字符串参数)"),e.createElementVNode("button",{type:"primary",onClick:n[3]||(n[3]=(...t)=>s.testDoSthWithJSON&&s.testDoSthWithJSON(...t))},"uts异步方法(json参数)")])])}]]);const S="uts.modules.utsAdvance",I="IndexKt",w=y(!1,{package:S,class:I,name:"doTimerTask"}),P=y(!1,{package:S,class:I,name:"doIntervalTask"});var N=r({data:()=>({title:"UTS进阶示例",taskId:0}),onUnload:function(){},methods:{testTimer:function(){w({start:function(t){uni.showToast({title:t,icon:"none"})},work:function(t){uni.showToast({title:t,icon:"none"})}})},testInterval:function(){var t=P({start:function(t){uni.showToast({title:t,icon:"none"})},work:function(t){uni.showToast({title:t,icon:"none"})}});this.taskId=t.taskId},testClearInterval:function(){o("log","at pages/tabBar/Advance/Advance.vue:62",this.taskId)}}},[["render",function(t,n,a,o,r,s){const c=l(e.resolveDynamicComponent("page-head"),i);return e.openBlock(),e.createElementBlock("view",null,[e.createVNode(c,{title:r.title},null,8,["title"]),e.createElementVNode("view",{class:"uni-btn-v uni-common-mt"},[e.createElementVNode("button",{type:"primary",onClick:n[0]||(n[0]=(...t)=>s.testTimer&&s.testTimer(...t))},"延迟任务"),e.createElementVNode("button",{type:"primary",onClick:n[1]||(n[1]=(...t)=>s.testInterval&&s.testInterval(...t))},"定时任务"),e.createElementVNode("button",{type:"primary",onClick:n[2]||(n[2]=(...t)=>s.testClearInterval&&s.testClearInterval(...t))},"关闭定时任务")])])}]]);const b=y(!1,{package:"uts.modules.utsOsapi",class:"IndexKt",name:"getBatteryCapacity"});var B=r({data:()=>({title:"系统API示例"}),onUnload:function(){},methods:{testGetBatteryCapacity:function(){var t=b();o("log","at pages/tabBar/SystemAPI/SystemAPI.vue:25",t),uni.showToast({title:"当前电量:"+t,icon:"none"})}}},[["render",function(t,n,a,o,r,s){const c=l(e.resolveDynamicComponent("page-head"),i);return e.openBlock(),e.createElementBlock("view",null,[e.createVNode(c,{title:r.title},null,8,["title"]),e.createElementVNode("view",{class:"uni-btn-v uni-common-mt"},[e.createElementVNode("button",{type:"primary",onClick:n[0]||(n[0]=(...t)=>s.testGetBatteryCapacity&&s.testGetBatteryCapacity(...t))},"获取电池电量")])])}]]);var E=r({data:()=>({}),methods:{}},[["render",function(t,n,a,o,r,i){return e.openBlock(),e.createElementBlock("view",null,[e.createElementVNode("text",null,"sdk集成")])}]]);__definePage("pages/tabBar/Primer/Primer",k),__definePage("pages/tabBar/Advance/Advance",N),__definePage("pages/tabBar/SystemAPI/SystemAPI",B),__definePage("pages/tabBar/SDKIntegration/SDKIntegration",E);const C={onLaunch:function(){o("log","at App.vue:4","App Launch")},onShow:function(){o("log","at App.vue:7","App Show")},onHide:function(){o("log","at App.vue:10","App Hide")}};const{app:T,Vuex:_,Pinia:V}={app:e.createVueApp(C)};uni.Vuex=_,uni.Pinia=V,T.provide("__globalStyles",__uniConfig.styles),T._component.mpType="app",T._component.render=()=>{},T.mount("#app")}(uni.VueShared,Vue);
...@@ -4,70 +4,28 @@ import kotlinx.coroutines.CoroutineScope; ...@@ -4,70 +4,28 @@ import kotlinx.coroutines.CoroutineScope;
import kotlinx.coroutines.Deferred; import kotlinx.coroutines.Deferred;
import kotlinx.coroutines.Dispatchers; import kotlinx.coroutines.Dispatchers;
import io.dcloud.uts.*; import io.dcloud.uts.*;
fun log(msg: String) { open class TimerOptions {
console.log(msg, "at uni_modules/uts-advance/app-android/utils.uts:2"); open lateinit var start: UTSCallback;
} open lateinit var work: UTSCallback;
open class AsyncOptions { }
open lateinit var type: String; fun doTimerTask(opts: TimerOptions): UtsJSONObject {
open lateinit var success: UTSCallback; opts.start("doTimerTask start");
open lateinit var fail: UTSCallback; setTimeout(fun() {
open lateinit var complete: UTSCallback; opts.work("doTimerTask work");
} }
val MAX = 100; , 2000);
fun testSync(msg: String): UtsJSONObject {
console.log("log test", "at uni_modules/uts-advance/app-android/index.uts:18");
log("log test1");
return object : UtsJSONObject() { return object : UtsJSONObject() {
var msg = """hello ${msg}""" var name = "doTimerTask"
}; };
} }
fun testSyncError() { fun doIntervalTask(opts: TimerOptions): UtsJSONObject {
val arr: MutableList<String> = mutableListOf(); var taskRet = setInterval(fun() {
console.log(arr[1], "at uni_modules/uts-advance/app-android/index.uts:29"); opts.work("doIntervalTask work");
} }
fun testSyncWithCallback(opts: AsyncOptions): UtsJSONObject { , 2000);
if (opts.type == "success") opts.success("success"); opts.start("doIntervalTask start");
else opts.fail("fail");
opts.complete("complete");
return object : UtsJSONObject() { return object : UtsJSONObject() {
var name = "testSyncWithCallback" var name = "doIntervalTask"
}; var taskId = taskRet
}
suspend fun testAsync(opts: AsyncOptions): Deferred<UtsJSONObject> = CoroutineScope(Dispatchers.Default).async {
if (opts.type == "success") opts.success("success");
else opts.fail("fail");
opts.complete("complete");
return@async object : UtsJSONObject() {
var name = "testAsync"
}; };
} }
open class TestOptions {
open lateinit var name: String;
open lateinit var callback: UTSCallback;
}
open class Test {
open var id: Number;
open var name: String;
constructor(id: Number, options: TestOptions){
this.id = id;
this.name = options.name;
options.callback("Test.constructor");
}
open fun testClassSyncWithCallback(opts: AsyncOptions): UtsJSONObject {
return testSyncWithCallback(opts);
}
open suspend fun testClassAsync(opts: AsyncOptions): Deferred<UtsJSONObject> = CoroutineScope(Dispatchers.Default).async {
val res = testAsync(opts).await();
return@async res;
}
companion object {
var type: String = "Test";
fun testClassStaticSyncWithCallback(opts: AsyncOptions): UtsJSONObject {
return testSyncWithCallback(opts);
}
suspend fun testClassStaticAsync(opts: AsyncOptions): Deferred<UtsJSONObject> = CoroutineScope(Dispatchers.Default).async {
val res = testAsync(opts).await();
return@async res;
}
}
}
...@@ -34,9 +34,9 @@ fun callWithoutParam(opts: NoParamOptions): UtsJSONObject { ...@@ -34,9 +34,9 @@ fun callWithoutParam(opts: NoParamOptions): UtsJSONObject {
var name = "doSthWithCallback" var name = "doSthWithCallback"
}; };
} }
fun callWithStringParam(opts: StringParamOptions): UtsJSONObject { fun callWithStringParam(input: String, success: (res: String) -> Unit): UtsJSONObject {
setTimeout(fun() { setTimeout(fun() {
opts.success(opts.input); success(input);
} }
, 500); , 500);
return object : UtsJSONObject() { return object : UtsJSONObject() {
......
...@@ -12,7 +12,7 @@ fun getBatteryCapacity(): String { ...@@ -12,7 +12,7 @@ fun getBatteryCapacity(): String {
if (context != null) { if (context != null) {
val manager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager; val manager = context.getSystemService(Context.BATTERY_SERVICE) as BatteryManager;
val currentLevel: Number = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY); val currentLevel: Number = manager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
return "" + currentLevel + "**456464%"; return "" + currentLevel + "%";
} }
return "0%"; return "0%";
} }
## 1 前置条件
+ 1 HX 3.5.6 之后版本
## 2 uts原生插件介绍
### 2.1 什么是uts原生插件
UTS= Uni Type Script.
UTS 插件是在uni原生插件的基础上,改用UTS作为插件开发语言。
进一步降低插件开发门槛,平台差异,执行效率的新型插件形式
![uts插件结构](./UTS结构示意图1.png)
### 2.2 uts原生插件与uni原生插件的区别
|-|传统原生插件|uts原生插件|
|-|-------|--------|
|开发语言|java/oc|uts|
|开发环境|Android studio/XCode|HBuilderX|
|打包方式|外挂aar 等产出物|编译时生成原生代码|
优点:
1 减少原生环境搭建环节,降低插件开发难度
2 进一步降低平台差异,一种语言开发两个平台插件
2 编译时生成原生代码,提高代码执行效率
## 3 UTS语法介绍
## 4 开发UTS插件
### 4.1 uni_modules
确保项目根目录存在uni_modules文件夹
![插件目录](./uni_modules.jpg)
`uni_modules`类似 NPM中的`node_modules`.是用来存放插件依赖的文件夹。
如果项目中已存在此目录,则跳过。如果不存在,在需要手动创建一个。
### 4.2 新建UTS插件
选中uni_modules文件夹 --> 右键新建插件
![新建插件1](./new_uts_plugin.jpg)
选择UTS原生插件
![新建插件2](./new_uts_plugin2.jpg)
插件目录结构
![新建插件3](./new_uts_plugin3.jpg)
### 4.3 清单文件package.json
package.json为插件的清单文件,里面说明了整个UTS插件的配置信息,下面是一个完整的示例
```
{
"id": "uts-helloworld",
"displayName": "uts-helloworld",
"version": "1.0.0",
"description": "uts-helloworld",
"keywords": [
"uts-helloworld"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
},
"dcloudext": {
"type": "native-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-vue": "u",
"app-nvue": "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"
}
}
},
"type": "uts",
"uts": {
"android": {
"libs": [],
"dependencies": []
},
"ios": {
"libs": []
}
}
}
}
```
## 5 使用插件
### 5.1 引用UTS插件
uts插件import有两种方式
import {a,b} from 'xxx'
```
import {
callWithoutParam,
callWithStringParam,
callWithJSONParam
} from "../../../uni_modules/uts-helloworld";
```
import X from 'XXX'
### 5.2 用法
延迟操作
```
//执行延迟操作
var timer = setTimeout(function, 1000);
//取消延迟操作
clearTimeout(timer);
```
定时操作
```
//执行定时操作
var timer = setInterval(function, 1000);
//取消定时操作
clearInterval(timer);
```
## 6 测试
### 5.1 真机运行
直接运行
### 5.2 云端打包
### 5.3 示例项目
### 一个简单的示例
### 插件目录结构
### 插件使用方法
完整的示例项目地址:
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册