1.1.16 • Published 2 years ago

smartyard-js v1.1.16

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Table of Contents generated with DocToc

JS API说明

引用说明

安装

通过npm安装

	npm i smartyard-js

本地文件引入

使用script标签引入

	<script src="./index.js"></script>

测试

Vue环境

	// Vue项目在main.js配置全局属性,即可全局引用
	// main.js
	import wzcc from "smartyard-js"
	Vue.use(wzcc)
	Vue.prototype.wzcc = wzcc;
	
	// 页面内调用jsapi方法
	this.wzcc.hello()

本地文件script标签引入

	// 本地文件script标签引入 调用对象wzcc
	wzcc.hello()

1. 业务逻辑类

1.1 wzcc.getUserToken

获取用户token

支持promise风格

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

Object.success 回调函数

参数

Object res

属性类型说明
codestring状态值: 200(成功);401(失败)
msgstring状态描述或失败原因
datastring结果内容

Object res.data

属性类型说明
access_tokenstring用户token值

1.2 wzcc.saveImage

保存图片至相册

不支持promise风格

参数

Object object

属性类型默认值必填说明
fileUrlstring图片网络地址
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

    wzcc.saveImage({
    	fileUrl: "https://t7.baidu.com/it/u=4162611394,4275913936&fm=193&f=GIF",
    	success: res=>{
    		console.log("保存图片成功")
    		wzcc.showToast("保存图片成功")
    	},
		fail: error=>{
			console.log("保存图片失败",error)
		}
    })

1.3 wzcc.getAppVersion

获取app版本信息(可用此方法判断是否为智慧大院app环境)

支持promise风格

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

Object.success 回调函数

参数

Object res

属性类型说明
codestring状态值: 200(成功);401(失败)
msgstring状态描述或失败原因
datastring结果内容

Object res.data

属性类型说明
namestringapp名称
versionstringapp版本号

示例代码

	wzcc.getAppVersion({
		success: res=>{
			console.log("getAppVersion",res)
			wzcc.showToast(res.data.name+" " +res.data.version)
		}
	})
	wzcc.getAppVersion().then(res=>{
		console.log("getAppVersion",res)
			wzcc.showToast(res.data.name+" " +res.data.version)
	})

1.4 wzcc.getAppVersionSync

同步获取app版本信息(可用此方法判断是否为智慧大院app环境)

Object 返回值

参数

Object res

属性类型说明
codestring状态值: 200(成功);401(失败)
msgstring状态描述或失败原因
datastring结果内容

Object res.data

属性类型说明
namestringapp名称
versionstringapp版本号

示例代码

	let res = wzcc.getAppVersionSync()
	console.log("getAppVersion",res)

1.5 wzcc.createOrder

一卡通预下单

不支持promise风格

请求参数

Object object

属性类型必填说明
ordersstring订单json数组
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

orders 订单json对象

属性类型必填说明
bizorgidstring商户号
orderAmountstring订单金额
orderNostring订单号
remarkstring订单备注 字数不超过100字

Object.success 回调函数

返回参数

Object res

属性类型说明
codestring状态码:200(成功);401(失败);
msgstring提示信息
datastring订单号对象

Object data

属性类型说明
tradeNostring交易单号
orderNostring业务系统提交的订单号

示例代码

	let order = {
		orders:[
		{
		    orderAmount: "0.01", //金额
		    orderNo:"TEST01", // 订单号
		    remark:"测试1",
			bizorgid: "229"
		},
		{
		    orderAmount: "0.02", //金额
		    orderNo:"TEST02", // 订单号
		    remark:"测试2",
			bizorgid: "230"
		},
		],
		success: res=>{
			console.log("createOrder",res)
			wzcc.showToast(res.msg)
		}
	}
	wzcc.createOrder(order)

1.6 wzcc.gotoAbcBankApp

前往农行app支付订单

支持promise风格

请求参数

Object object

属性类型必填说明
orderTokenstring农行预下单的订单token值
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

Object.success 回调函数

返回参数

Object res

属性类型说明
codestring状态码:200(成功);401(失败);
msgstring提示信息

示例代码

	wzcc.gotoAbcBankApp({
		orderToken: "12345667",
		success: (res)=>{
			console.log("gotoabcapp success",res)
		},
		fail: (err)=>{
			console.log("gotoabcapp fail",err)
		}
	})
	wzcc.gotoAbcBankApp({
		orderToken: "12345667"
	}).then(res=>{
		console.log("gotoabcapp",res)
	})

2. 设备

2.1 wzcc.getNetworkType

获取网络类型

支持promise风格

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

Object.success 回调函数

参数

Object res

属性类型说明
codestring状态值: 200(成功);401(失败)
msgstring状态描述或失败原因
datastring结果内容

Object res.data

属性类型说明
networkTypestring网络类型

data.networkType值枚举

类型
wifistring
4Gstring
5Gstring
网络不可用string
网络未连接string
未知网络string

示例代码

    wzcc.getNetworkType({
        success: function(res){
            const networkType = res.data.networkType
        },
        fail: function(error){
        }
    })
    
    wzcc.getNetworkType().then(res=>{
        const networkType = res.data.networkType
    })

2.2 wzcc.setStatusBarLightMode

设置设备状态栏浅色/深色模式

支持promise风格

参数

Object object

属性类型默认值必填说明
modestring默认值:light;可选值:light;dark
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

    wzcc.setStatusBarLightMode({
		type: "dark",
        success: function(res){
        },
        fail: function(error){
        }
    })
    
    wzcc.setStatusBarLightMode({
		type: "dark"
	}).then(res=>{
        
    })

2.3 wzcc.setStatusBarColor

设置设备状态栏颜色

支持promise风格

参数

Object object

属性类型默认值必填说明
colorstring默认值:app主题色;请传6位标准的16进制格式颜色值,否则无法解析,示例:#ffffff
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

    wzcc.setStatusBarColor({
		color: "#2684FF",
        success: function(res){
        },
        fail: function(error){
        }
    })
    
    wzcc.setStatusBarLightMode({
		type: "#000000"
	}).then(res=>{
        
    })

2.4 wzcc.showStatusBar

设置设备状态栏显示/隐藏

支持promise风格

参数

Object object

属性类型默认值必填说明
showstring默认值:true;可选值:true,false
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

    wzcc.showStatusBar({
		show: "true",
        success: function(res){
        },
        fail: function(error){
        }
    })
    
    wzcc.showStatusBar({
		show: "true"
	}).then(res=>{
        
    })

2.5 wzcc.getSystemInfo

获取设备基础信息

支持promise风格

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

Object.success 回调函数

参数

Object res

属性类型说明
codestring状态值: 200(成功);401(失败)
msgstring状态描述或失败原因
datastring结果内容

Object res.data

属性类型说明
screenWidthstring屏幕的宽度(单位:px)
screenHeightstring屏幕的高度(单位:px)
windowWidthstring应用屏幕的宽度(单位:px)
windowHeightstring应用屏幕的高度(单位:px)
statusBarHeightstring状态栏高度(单位:px)
sdkVersionstring设备系统版本号
macAddressstring设备 MAC 地址
modelstring设备型号
systemstring系统平台

示例代码

    wzcc.getSystemInfo({
        success: function(res){
			console.log("system",res.data)
        },
        fail: function(error){
        }
    })
    
    wzcc.getSystemInfo({
	}).then(res=>{
        console.log("system",res.data)
    })

2.6 wzcc.vibrate

设备震动

支持promise风格

参数

Object object

属性类型默认值必填说明
lastTimeint震动时长,单位ms,默认1000ms
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

    wzcc.vibrate({
		lastTime: 2000,
        success: function(res){
			console.log(res)
        },
        fail: function(error){
        }
    })
    
    wzcc.vibrate({
	}).then(res=>{
        console.log(res)
    })

2.7 wzcc.addPhoneContact

添加联系人到设备通讯录

不支持promise风格

参数

Object object

属性类型默认值必填说明
firstNamestring联系人名字
lastNamestring联系人姓氏
mobilePhonestring联系人手机号码
remarkstring联系人备注
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

注意: 虽然每个参数都非必填,但为了联系人可以正常创建,姓氏、名字、手机号码此三项至少填写一项,否则会报错

示例代码

    wzcc.addPhoneContact({
		firstName: "三",
		lastName: "张",
		mobilePhone: "18900001111",
		remark: "测试联系人",
        success: function(res){
			console.log(res)
        },
        fail: function(error){
        }
    })
    
    wzcc.addPhoneContact({
		firstName: "张三",
		mobilePhone: "18900001111",
	}).then(res=>{
        console.log(res)
    })

2.8 wzcc.callPhone

拨打电话

不支持promise风格

参数

Object object

属性类型默认值必填说明
phonestring要拨打的电话号码
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

    wzcc.callPhone({
		phone: "123456"
    })

2.9 wzcc.showSafeArea

设置设备安全区域显示/隐藏

支持promise风格

参数

Object object

属性类型默认值必填说明
showstring默认值:false;可选值:true,false
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

    wzcc.showSafeArea({
		show: "false",
        success: function(res){
        },
        fail: function(error){
        }
    })
    
    wzcc.showSafeArea({
		show: "false"
	}).then(res=>{
        
    })

3. 界面交互

3.1 wzcc.showToast

显示消息提示框

参数

Object object

属性类型默认值必填说明
messagestring提示的内容

示例代码

    wzcc.showToast("你好")

3.2 wzcc.scanCode

调起客户端扫码界面进行扫码

不支持promise风格

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

Object.success 回调函数

参数

Object res

属性类型说明
codestring状态值: 200(成功);401(失败)
msgstring状态描述或失败原因
datastring结果内容

Object res

属性类型说明
resultstring扫码结果

示例代码

    wzcc.scanCode({
        success: function(res){
            const result = res.result
        },
        fail: function(error){
        }
    })

3.3 wzcc.closeWebView

关闭整个webview页面

示例代码

    wzcc.closeWebView()

3.4 wzcc.goBack

webview回退

示例代码

    wzcc.goBack()

3.5 wzcc.gotoBrowser

跳转至外部浏览器

支持promise风格

参数

Object object

属性类型默认值必填说明
urlstring请输入准确的网页地址
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

    wzcc.gotoBrowser({
    	url:"https://www.baidu.com"
    }).then(res=>{
    	console.log("跳转成功")
    })
    
    wzcc.gotoBrowser({
    	url:"https://www.baidu.com",
		success: res=>{
			console.log("跳转成功")
		}
    })

4. 位置定位

4.1 wzcc.getLocation

定位当前GPS坐标

不支持promise风格

参数

Object object

属性类型默认值必填说明
successfunction接口调用成功的回调函数
failfunction接口调用失败的回调函数
completefunction接口调用结束的回调函数(调用成功、失败都会执行)

Object.success 回调函数

参数

Object res

属性类型说明
codestring状态值: 200(成功);401(失败)
msgstring状态描述或失败原因
datastring结果内容

Object res.data

属性类型说明
longitudestring经度
latitudestring纬度

注意: 目前支持的定位坐标类型为gcj02

示例代码

    wzcc.getLocation({
    	success: res=>{
    		console.log("gps",res.longitude+","+res.latitude)
    	},
    	fail: error=>{
    		console.log(error)
    	}
    })

1.1.16

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.15

2 years ago

1.1.14

2 years ago

1.1.13

2 years ago

1.1.10

3 years ago

1.1.9

3 years ago

1.1.8

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.3

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

1.1.2

3 years ago

1.0.0

3 years ago