0
点赞
收藏
分享

微信扫一扫

ScripTable ios控件自定义教程 JS

栖桐 2022-02-16 阅读 100

官网:可编写脚本文档

这是一款可让您使用 JavaScript 自动化 iOS 的应用程序

Get请求案例

// 创建组件
let w = await createWidget();
// 将组件显示为中等
await w.presentMedium();
// 如果在快捷指令中运行的话,在弹窗中显示此小组件
Script.setWidget(w);

// 从API获取热榜
async function get_hot() {
    let req = new Request("// width: 分割线的长度
const width = 150;
// h: 分割线的宽度
h=0.1
// 创建组件
let w = await createWidget();
// 将组件显示为中等
await w.presentMedium();
// 如果在快捷指令中运行的话,在弹窗中显示此小组件
Script.setWidget(w);

// 从API获取知乎热榜
async function get_hot() {
    let req = new Request("https://www.zhihu.com/api/v3/feed/topstory/hot-lists/total?limit=50&desktop=true")
    req.headers = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36"
    }
    return req.loadJSON()
}

async function createWidget() {
    let list = new ListWidget();
    list.backgroundColor = new Color("#3ca4fe", 0.6);
    let stack = list.addStack();
    // 水平居中
    stack.centerAlignContent();
    // 显示数据
    let hot_list = (await get_hot()).data;
    let main_title = list.addText(JSON.stringify(hot_list));
    main_title.font = new Font("PingFang SC", 20);
    return list
}

Pet请求案例

测试数据

{
	"code": 0,
	"data": {
		"icon": "taxi",
		"totalKm": "360.54",
		"imsi": "460048290108183",
		"deviceName": "浙A•1V15X",
		"accFlag": "1",
		"speed": "3",
		"posType": "GPS",
		"iccid": "89860462042080058183",
		"powerStatus": "0",
		"gPSSignal": "4",
		"sim": "物联卡",
		"surplusTime": "",
		"vehicleNumber": "浙A•1V15X",
		"reMark": "",
		"lat": 30.276191,
		"deviceType": "car",
		"vehicleColor": "星月白",
		"isSleep": 0,
		"hbTime": "2022-02-16 13:22:23",
		"locationTime": "2022-02-16 08:22:00",
		"lng": 119.941044,
		"simExpiration": "2022-06-30 23:59:59",
		"allIcon": "automobile,truck,bus,taxi,mtc,per,cow,plane,policeCar,policeMtc,other,ship,electric,excavator,train",
		"showTemAndHum": 1,
		"mcType": "JM-V340",
		"accStatus": "0",
		"installPosition": "副驾驶手套箱",
		"electQuantity": "29",
		"allIconName": "[{\"name\":\"轿车\",\"type\":\"automobile\"},{\"name\":\"货车\",\"type\":\"truck\"},{\"name\":\"客车\",\"type\":\"bus\"},{\"name\":\"出租车\",\"type\":\"taxi\"},{\"name\":\"摩托车\",\"type\":\"mtc\"},{\"name\":\"人\",\"type\":\"per\"},{\"name\":\"动物\",\"type\":\"cow\"},{\"name\":\"无人机\",\"type\":\"plane\"},{\"name\":\"警车\",\"type\":\"policeCar\"},{\"name\":\"警用摩托\",\"type\":\"policeMtc\"},{\"name\":\"其他\",\"type\":\"other\"},{\"name\":\"船\",\"type\":\"ship\"},{\"name\":\"电动车\",\"type\":\"electric\"},{\"name\":\"挖掘机\",\"type\":\"excavator\"},{\"name\":\"火车\",\"type\":\"train\"}]",
		"speedType": "0",
		"imei": "868120272076230",
		"simActivaction": "2021-07-02 00:00:00",
		"isProbation": false,
		"expiration": "2041-12-14 23:59:59",
		"simStatus": "1",
		"driverName": "宋师傅",
		"driverPhone": "13282148187",
		"activationFlag": "1",
		"status": 1
	},
	"dataTotalRows": "",
	"msg": "查询成功",
	"ok": true,
	"result": "",
	"totalDistiance": "",
	"totalTime": ""
}
举报

相关推荐

0 条评论