Commit 6e5044e3 by 韩达

标签补打

parent 8c21b5de
{
"name": "wmsApp",
"appid": "__UNI__655E80D",
"description": "",
"versionName": "1.0.0",
"versionCode": "100",
"transformPx": false,
"name" : "wmsApp",
"appid" : "__UNI__655E80D",
"description" : "",
"versionName" : "1.0.0",
"versionCode" : "100",
"transformPx" : false,
/* 5+App特有相关 */
"app-plus": {
"usingComponents": true,
"nvueStyleCompiler": "uni-app",
"compilerVersion": 3,
"splashscreen": {
"alwaysShowBeforeRender": true,
"waiting": true,
"autoclose": true,
"delay": 0
"app-plus" : {
"usingComponents" : true,
"nvueStyleCompiler" : "uni-app",
"compilerVersion" : 3,
"splashscreen" : {
"alwaysShowBeforeRender" : true,
"waiting" : true,
"autoclose" : true,
"delay" : 0
},
/* 模块配置 */
"modules": {},
"modules" : {},
/* 应用发布信息 */
"distribute": {
"distribute" : {
/* android打包配置 */
"android": {
"permissions": [
"android" : {
"permissions" : [
"<uses-permission android:name=\"android.permission.CHANGE_NETWORK_STATE\"/>",
"<uses-permission android:name=\"android.permission.MOUNT_UNMOUNT_FILESYSTEMS\"/>",
"<uses-permission android:name=\"android.permission.VIBRATE\"/>",
......@@ -41,47 +41,47 @@
]
},
/* ios打包配置 */
"ios": {
"dSYMs": false
"ios" : {
"dSYMs" : false
},
/* SDK配置 */
"sdkConfigs": {
"ad": {}
"sdkConfigs" : {
"ad" : {}
}
},
"nvueLaunchMode": ""
"nvueLaunchMode" : ""
},
/* 快应用特有相关 */
"quickapp": {},
"quickapp" : {},
/* 小程序特有相关 */
"mp-weixin": {
"appid": "wx61a41a064fa2fb3c",
"setting": {
"urlCheck": false,
"postcss": true,
"es6": false,
"minified": true
"mp-weixin" : {
"appid" : "wx61a41a064fa2fb3c",
"setting" : {
"urlCheck" : false,
"postcss" : true,
"es6" : false,
"minified" : true
},
"usingComponents": true
"usingComponents" : true
},
"mp-alipay": {
"usingComponents": true
"mp-alipay" : {
"usingComponents" : true
},
"mp-baidu": {
"usingComponents": true
"mp-baidu" : {
"usingComponents" : true
},
"mp-toutiao": {
"usingComponents": true
"mp-toutiao" : {
"usingComponents" : true
},
"uniStatistics": {
"enable": false
"uniStatistics" : {
"enable" : false
},
"vueVersion": "2",
"quickapp-webview": {
"icon": "wms",
"package": "com.liexin.wms",
"versionName": "1.0",
"minPlatformVersion": "1.0"
"vueVersion" : "2",
"quickapp-webview" : {
"icon" : "wms",
"package" : "com.liexin.wms",
"versionName" : "1.0",
"minPlatformVersion" : "1.0"
},
"fallbackLocale": "zh-Hans"
"fallbackLocale" : "zh-Hans"
}
......@@ -2,9 +2,9 @@
<view class="repairPrint">
<view class="search-box row bothSide verCenter">
<view class="sn row rowCenter verCenter">
<picker @change="bindPickerChange" :value="index" :range="array">
<picker @change="bindPickerChange" v-model="id" data-type_id="id" :value="index" :range="labelStyles" range-key="name">
<view class="row verCenter">
<view class="uni-input">{{ array[index] }}</view>
<view class="uni-input">{{ labelStyles[index].name }}</view>
<view class="uni-arrow"></view>
</view>
</picker>
......@@ -12,30 +12,93 @@
<view class="search-bar row bothSide verCenter">
<view class="row verCenter">
<text class="iconfont icon-juxing1"></text>
<input class="uni-input" placeholder="请输入号码" placeholder-style="color:#919399" />
<input class="uni-input" v-model="formParams.sn" placeholder="请输入号码" placeholder-style="color:#919399" />
</view>
<text class="iconfont icon-a-juxing11"></text>
</view>
<view class="search-bar row bothSide verCenter">
<view class="row verCenter">
<text class="iconfont icon-juxing1"></text>
<input class="uni-input" v-model="formParams.print_num" placeholder="数量" placeholder-style="color:#919399" />
</view>
<text class="iconfont icon-a-juxing11"></text>
</view>
<view class="fix-btn row rowCenter verCenter">打印</view>
</view>
<view class="fix-btn row rowCenter verCenter" @click="latePrint()">打印</view>
</view>
</template>
<script>
import { API } from '@/util/api.js';
import { getLocalIpAddress } from '@/util/util.js';
export default {
data() {
return {
index: 0,
array: ['入库标签', '容器标签', '客户专用标签']
labelStyles: [
{
'id': 5,
'name': '入库标签',
},
{
'id': 1,
'name': '库位标签',
},
{
'id': 2,
'name': '库区标签',
},
{
'id': 3,
'name': '区域标签',
},
{
'id': 4,
'name': '容器标签',
},
],
formParams: {
sn: '',
origin_device_ip: '',
print_num: '',
type: ''
}
};
},
onLoad() {},
onLoad(options) {
this.formParams.type = this.labelStyles[0].id;
},
methods: {
bindPickerChange: function(e) {
console.log('picker发送选择改变,携带值为', e.detail.value);
console.log('picker发送选择改变,id为', this.labelStyles[e.detail.value].id);
this.index = e.detail.value;
this.formParams.type = this.labelStyles[e.detail.value].id;
},
/**
* 打印
*/
latePrint() {
this.formParams.origin_device_ip = getLocalIpAddress() ?? '';
console.log('origin_device_ip', this.formParams.origin_device_ip)
this.request(API.latePrint, 'POST', this.formParams, true).then(res => {
if (res.code === 0) {
uni.showToast({
title: '正在补打...',
icon: 'success'
});
} else {
uni.showToast({
title: res.msg,
icon: 'error'
});
}
});
},
}
};
</script>
......
{
"appid": "wx849381373e3e156a",
"compileType": "miniprogram",
"libVersion": "2.31.1",
"packOptions": {
"ignore": [],
"include": []
},
"setting": {
"coverView": true,
"es6": true,
"postcss": true,
"minified": true,
"enhance": true,
"showShadowRootInWxmlPanel": true,
"packNpmRelationList": [],
"babelSetting": {
"ignore": [],
"disablePlugins": [],
"outputPath": ""
},
"condition": false
},
"condition": {},
"editorSetting": {
"tabIndent": "insertSpaces",
"tabSize": 2
}
}
\ No newline at end of file
{
"description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
"projectname": "wmsApp",
"setting": {
"compileHotReLoad": true
}
}
\ No newline at end of file
## 1.0.3(2023-04-07)
修复 getConnectedWifi 返回数据错误的问题
## 1.0.0(2022-12-05)
实现Android/iOS平台Wi-Fi功能模块
注:iOS平台仅支持获取已连接的 Wi-Fi 信息
{
"id": "uni-wifi",
"displayName": "uni-wifi",
"version": "1.0.3",
"description": "wifi管理",
"keywords": [
"wifi"
],
"repository": "",
"engines": {
"HBuilderX": "^3.6.11"
},
"dcloudext": {
"type": "uts",
"sale": {
"regular": {
"price": "0.00"
},
"sourcecode": {
"price": "0.00"
}
},
"contact": {
"qq": ""
},
"declaration": {
"ads": "无",
"data": "插件不采集任何数据",
"permissions": "Android平台:\n<uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\"/>\n<uses-permission android:name=\"android.permission.CHANGE_WIFI_STATE\"/>\n<uses-permission android:name=\"android.permission.ACCESS_FINE_LOCATION\"/>\n<uses-permission android:name=\"android.permission.ACCESS_COARSE_LOCATION\"/>\niOS平台:\niOS13及以上平台获取Wifi信息需要定位权限"
},
"npmurl": ""
},
"uni_modules": {
"uni-ext-api":{
"uni": {
"startWifi": "startWifi",
"stopWifi": "stopWifi",
"connectWifi":"connectWifi",
"getConnectedWifi": "getConnectedWifi",
"getWifiList":"getWifiList",
"onGetWifiList":"onGetWifiList",
"offGetWifiList":"offGetWifiList",
"onWifiConnected":"onWifiConnected",
"offWifiConnected":"offWifiConnected",
"onWifiConnectedWithPartialInfo":"onWifiConnectedWithPartialInfo",
"offWifiConnectedWithPartialInfo":"offWifiConnectedWithPartialInfo"
}
},
"dependencies": [],
"encrypt": [],
"platforms": {
"cloud": {
"tcb": "y",
"aliyun": "y"
},
"client": {
"Vue": {
"vue2": "y",
"vue3": "y"
},
"App": {
"app-android": {
"minVersion": "19"
},
"app-ios": {
"minVersion": "9"
}
},
"H5-mobile": {
"Safari": "n",
"Android Browser": "n",
"微信浏览器(Android)": "n",
"QQ浏览器(Android)": "n"
},
"H5-pc": {
"Chrome": "n",
"IE": "n",
"Edge": "n",
"Firefox": "n",
"Safari": "n"
},
"小程序": {
"微信": "n",
"阿里": "n",
"百度": "n",
"字节跳动": "n",
"QQ": "n",
"钉钉": "n",
"快手": "n",
"飞书": "n",
"京东": "n"
},
"快应用": {
"华为": "n",
"联盟": "n"
}
}
}
}
}
\ No newline at end of file
## 使用说明
Wi-Fi功能模块
### App-iOS平台注意事项
- iOS平台App获取Wi-Fi信息需要开启“Access WiFi information”能力
登录苹果开发者网站,在“Certificates, Identifiers & Profiles”页面选择“Identifiers”中选择对应的App ID,确保开启“Access WiFi information”,保存后重新生成profile文件
- iOS13及以上系统,获取当前连接的Wi-Fi信息需要先获取系统定位权限,因此在iOS13及以上系统使用此接口时,会触发定位权限申请的弹窗
### App-Android平台注意事项
- 如果是自定义基座,需要具备下面的权限
```
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
```
###uni.startWifi(OBJECT)
初始化Wi-Fi模块。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#startwifi](https://uniapp.dcloud.net.cn/api/system/wifi.html#startwifi)
### uni.stopWifi(OBJECT)
关闭 Wi-Fi 模块。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#stopwifi](https://uniapp.dcloud.net.cn/api/system/wifi.html#stopwifi)
### uni.getConnectedWifi(OBJECT)
获取已连接的 Wi-Fi 信息
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#getconnectedwifi](https://uniapp.dcloud.net.cn/api/system/wifi.html#getconnectedwifi)
### uni.getWifiList(OBJECT)
请求获取 Wi-Fi 列表。wifiList 数据会在 onGetWifiList 注册的回调中返回。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#getWifiList](https://uniapp.dcloud.net.cn/api/system/wifi.html#getWifiList)
**平台差异说明**
|App-Android|App-iOS|
|:-:|:-:|
|√|x|
### uni.onGetWifiList(CALLBACK)
监听获取到 Wi-Fi 列表数据事件。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#onGetWifiList](https://uniapp.dcloud.net.cn/api/system/wifi.html#onGetWifiList)
**平台差异说明**
|App-Android|App-iOS|
|:-:|:-:|
|√|x|
### uni.offGetWifiList(CALLBACK)
移除获取到 Wi-Fi 列表数据事件的监听函数。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#offGetWifiList](https://uniapp.dcloud.net.cn/api/system/wifi.html#offGetWifiList)
**平台差异说明**
|App-Android|App-iOS|
|:-:|:-:|
|√|x|
### uni.connectWifi(OBJECT)
连接 Wi-Fi。若已知 Wi-Fi 信息,可以直接利用该接口连接。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi](https://uniapp.dcloud.net.cn/api/system/wifi.html#connectWifi)
**平台差异说明**
|App-Android|App-iOS|
|:-:|:-:|
|√|x|
### uni.onWifiConnected(CALLBACK)
监听连接上 Wi-Fi 的事件。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnected](https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnected)
**平台差异说明**
|App-Android|App-iOS|
|:-:|:-:|
|√|x|
### uni.offWifiConnected(CALLBACK)
移除连接上 Wi-Fi 的事件的监听函数。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnected](https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnected)
**平台差异说明**
|App-Android|App-iOS|
|:-:|:-:|
|√|x|
### uni.onWifiConnectedWithPartialInfo(CALLBACK)
监听连接上 Wi-Fi 的事件。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnectedWithPartialInfo](https://uniapp.dcloud.net.cn/api/system/wifi.html#onWifiConnectedWithPartialInfo)
**平台差异说明**
|App-Android|App-iOS|
|:-:|:-:|
|√|x|
### uni.offWifiConnectedWithPartialInfo(CALLBACK)
移除连接上 Wi-Fi 的事件的监听函数。
> 使用文档:[https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnectedWithPartialInfo](https://uniapp.dcloud.net.cn/api/system/wifi.html#offWifiConnectedWithPartialInfo)
**平台差异说明**
|App-Android|App-iOS|
|:-:|:-:|
|√|x|
{
"minSdkVersion": "19"
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>使用期间获取位置权限</string>
</dict>
</plist>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.networking.wifi-info</key>
<true/>
</dict>
</plist>
\ No newline at end of file
{
"frameworks": [
"CoreLocation",
"SystemConfiguration"
],
"validArchitectures": [
"arm64", "armv7" ],"deploymentTarget": "9"
}
\ No newline at end of file
import { CLLocationManager, CLAuthorizationStatus, CLLocationManagerDelegate } from 'CoreLocation'
import { CaptiveNetwork, kCNNetworkInfoKeySSID, kCNNetworkInfoKeyBSSID } from 'SystemConfiguration.CaptiveNetwork';
import { NSArray, NSDictionary } from 'Foundation';
import { CFString } from 'CoreFoundation';
import { UIDevice } from 'UIKit';
import { WifiOption, WifiConnectOption, GetConnectedWifiOptions, UniWifiInfo, UniWifiResult, UniWifiCallback, StartWifi, StopWifi, GetWifiList, OnGetWifiList, OffGetWifiList, GetConnectedWifi, ConnectWifi, OnWifiConnected, OnWifiConnectedWithPartialInfo, OffWifiConnected, OnOffWifiConnectedWithPartialInfo, SetWifiList } from "../interface.uts"
/*
* 系统定位权限获取类
*/
class LocationPromiseService implements CLLocationManagerDelegate {
static promiseCompletionHandler: ((res: boolean)=>void)[] = []
manager?: CLLocationManager
constructor(manager?: CLLocationManager) {
this.manager = manager
}
initlizeManager(): boolean {
if (this.manager == null) {
this.manager = new CLLocationManager()
this.manager!.delegate = this
}
return true
}
locationManager(manager: CLLocationManager, @argumentLabel("didChangeAuthorization") status: CLAuthorizationStatus) {
if (status == CLAuthorizationStatus.authorizedAlways || status == CLAuthorizationStatus.authorizedWhenInUse) {
LocationPromiseService.promiseCompletionHandler.forEach((handler): void => {
handler(true)
})
} else if (status == CLAuthorizationStatus.notDetermined) {
manager.requestWhenInUseAuthorization()
} else if (status == CLAuthorizationStatus.denied) {
LocationPromiseService.promiseCompletionHandler.forEach((handler): void => {
handler(false)
})
}
}
requestPromise(@escaping completion: (res: boolean)=>void) {
let status: CLAuthorizationStatus = CLLocationManager.authorizationStatus()
if (status == CLAuthorizationStatus.notDetermined) {
if (this.initlizeManager() == true) {
this.manager!.requestWhenInUseAuthorization()
LocationPromiseService.promiseCompletionHandler.push(completion)
}
} else if (status == CLAuthorizationStatus.authorizedAlways || status == CLAuthorizationStatus.authorizedWhenInUse) {
completion(true)
} else if (status == CLAuthorizationStatus.denied) {
if (CLLocationManager.locationServicesEnabled() == false && this.initlizeManager() == true) {
this.manager!.requestWhenInUseAuthorization()
LocationPromiseService.promiseCompletionHandler.push(completion)
}
}
}
}
const locationPromiseService: LocationPromiseService = new LocationPromiseService(null)
/*
* 获取系统定位权限
*/
function requestLocationPromise(@escaping completion: (res: boolean)=>void) {
locationPromiseService.requestPromise(completion)
}
/*
* 获取当前连接的wifi信息(通过定位权限)
*/
function fetchConnectedWifiWithLocationPromise(option: GetConnectedWifiOptions) {
let arr = CNCopySupportedInterfaces()
let wifiInfo: UniWifiInfo = {
BSSID: "",
SSID: "",
secure: false,
signalStrength: 0,
frequency: 0
}
if (arr != null) {
let list = arr! as NSArray
let index = 0
while (index < list.count) {
let item = list[index]
let interfaceName = item as string
let dic = CNCopyCurrentNetworkInfo(interfaceName as CFString)
if (dic != null) {
let dict = dic! as NSDictionary
let SSID = dict[kCNNetworkInfoKeySSID as string]
let BSSID = dict[kCNNetworkInfoKeyBSSID as string]
if (SSID != null && BSSID != null) {
let ssid = SSID! as string
let bssid = BSSID! as string
wifiInfo.SSID = ssid
wifiInfo.BSSID = bssid
wifiInfo.secure = false
wifiInfo.signalStrength = 0
wifiInfo.frequency = 0
break;
}
}
index++
}
if (wifiInfo.BSSID!.length > 0 && wifiInfo.SSID.length > 0) {
let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi",
errCode: 0,
errMsg: "getConnectedWifi:ok",
wifi: wifiInfo,
}
option.success?.(res)
option.complete?.(res)
}else {
const res: UniWifiResult = {
errSubject: "uni-getConnectedWifi",
errCode: 12010,
errMsg: "getConnectedWifi:system internal error",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
}
}else {
const res: UniWifiResult = {
errSubject: "uni-getConnectedWifi",
errCode: 12010,
errMsg: "getConnectedWifi:system internal error",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
}
}
/*
* 保存全局数据信息
*/
class UniWiFiModuleGloabInfo {
static alreadyStartWifi: boolean = false
}
/* =================================== 对外暴露的接口 ==============================================*/
/*
* 初始化wifi模块
*/
export const startWifi: StartWifi = function (option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = true
let res: UniWifiResult = {
errSubject: "uni-startWifi",
errCode: 0,
errMsg: "startWifi:ok",
wifi: null
}
option.success?.(res)
option.complete?.(res)
}
/*
* 停止wifi模块
*/
export const stopWifi: StopWifi = function (option: WifiOption) {
UniWiFiModuleGloabInfo.alreadyStartWifi = false
LocationPromiseService.promiseCompletionHandler = []
let res: UniWifiResult = {
errSubject: "uni-stopWifi",
errCode: 0,
errMsg: "stopWifi:ok",
wifi: null
}
option.success?.(res)
option.complete?.(res)
}
/*
* 获取wifi列表, 在调用之前需要引导用户跳转到系统设置-WIFI设置页面,系统搜索周边wifi后app才能接收到回调
*/
export const getWifiList: GetWifiList = function (option: WifiOption) {
let res: UniWifiResult = {
errSubject: "uni-getWifiList",
errCode: 12001,
errMsg: "getWifiList:system not support",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
}
/* 获取wifi列表的回调
* note: 请在getWifiList方法的回调里调用该方法
*/
export const onGetWifiList: OnGetWifiList = function (callback: UniWifiCallback) {
}
/*
* 注销获取wifi列表的回调
*/
export const offGetWifiList: OffGetWifiList = function (callback: UniWifiCallback) {
}
/*
* 获取当前连接的wifi信息
*/
export const getConnectedWifi: GetConnectedWifi = function (option: GetConnectedWifiOptions) {
if (UniWiFiModuleGloabInfo.alreadyStartWifi == false) {
let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi",
errCode: 12000,
errMsg: "getConnectedWifi:not init",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
} else{
if (UIDevice.current.systemVersion >= "13.0") {
requestLocationPromise((success) => {
if (success == true) {
fetchConnectedWifiWithLocationPromise(option)
}else {
let res: UniWifiResult = {
errSubject: "uni-getConnectedWifi",
errCode: 12007,
errMsg: "getConnectedWifi:user denied",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
}
})
} else{
fetchConnectedWifiWithLocationPromise(option)
}
}
}
/*
* 连接wifi
*/
export const connectWifi: ConnectWifi = function (option: WifiConnectOption) {
let res: UniWifiResult = {
errSubject: "uni-connectWifi",
errCode: 12001,
errMsg: "connectWifi:system not support",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
}
/*
* 连上wifi事件的监听函数
*/
export const onWifiConnected: OnWifiConnected = function (callback: UniWifiCallback) {
}
/*
* 连上wifi事件的监听函数, wifiInfo仅包含ssid
*/
export const onWifiConnectedWithPartialInfo: OnWifiConnectedWithPartialInfo = function (callback: UniWifiCallback) {
}
/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
export const offWifiConnected: OffWifiConnected = function (callback: UniWifiCallback | null) {
}
/*
* 移除连接上wifi的事件的监听函数,不传此参数则移除所有监听函数。
*/
export const onOffWifiConnectedWithPartialInfo: OnOffWifiConnectedWithPartialInfo = function (callback: UniWifiCallback | null) {
}
/*
* 设置 wifiList 中 AP 的相关信息。在 onGetWifiList 回调后调用,iOS特有接口。
*/
export const setWifiList: SetWifiList = function (option: WifiOption) {
let res: UniWifiResult = {
errSubject: "uni-setWifiList",
errCode: 12001,
errMsg: "setWifiList:system not support",
wifi: null
}
option.fail?.(res)
option.complete?.(res)
}
\ No newline at end of file
/**
* Wifi 函数通用入参封装
*/
export type WifiOption = {
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
};
/**
* Wifi 链接参数封装
*/
export type WifiConnectOption = {
SSID?: string;
BSSID?: string;
password?: string;
maunal?: boolean;
partialInfo?: boolean; //ios不生效
success?: (res: UniWifiResult) => void;
fail?: (res: UniWifiResult) => void;
complete?: (res: UniWifiResult) => void;
}
/**
* 获取当前链接的wifi信息
*/
export type GetConnectedWifiOptions = {
partialInfo?: boolean
success?: (res: UniWifiResult) => void
fail?: (res: UniWifiResult) => void
complete?: (res: UniWifiResult) => void
}
/*
* 对外暴露的wifi信息
*/
export type UniWifiInfo = {
SSID: string;
BSSID?: string;
secure?: boolean;
signalStrength?: number;
frequency?: number;
}
export type UniWifiResult = {
errCode : number,
errSubject : string,
errMsg : string,
wifi: UniWifiInfo | null
}
export type UniWifiCallback = () => void
export type StartWifi = (option: WifiOption) => void
export type StopWifi = (option: WifiOption) => void
export type GetWifiList = (option: WifiOption) => void
export type OnGetWifiList = (callback: UniWifiCallback) => void
export type OffGetWifiList = (callback: UniWifiCallback) => void
export type GetConnectedWifi = (option: GetConnectedWifiOptions) => void
export type ConnectWifi = (option: WifiConnectOption) => void
export type OnWifiConnected = (callback: UniWifiCallback) => void
export type OnWifiConnectedWithPartialInfo = (callback: UniWifiCallback) => void
export type OffWifiConnected = (callback: UniWifiCallback | null) => void
export type OnOffWifiConnectedWithPartialInfo = (callback: UniWifiCallback | null) => void
export type SetWifiList = (option: WifiOption) => void
interface Uni {
startWifi : StartWifi,
stopWifi : StopWifi,
/**
* @autotest {
generated: false,
pollution: false,
cases:[
{
before: 'startWifi',
after: 'stopWifi',
input: [{
maunal:false,
SSID:"Xiaomi_20D0",
password:"streamApp!2016",
}],
output:{
callbackType: 'success',
value: { errCode: 12013 ,errMsg: "connectWifi:wifi config may be expired",errSubject: "uni-connectWifi"}
}
}
]
}
*/
connectWifi: ConnectWifi,
/**
* @autotest {
generated: false,
cases:[
{
before: 'startWifi',
after: 'stopWifi'
}
]
}
*/
getWifiList : GetWifiList,
onGetWifiList : OnGetWifiList,
offGetWifiList : OffGetWifiList,
getConnectedWifi : GetConnectedWifi,
onWifiConnected : OnWifiConnected,
onWifiConnectedWithPartialInfo : OnWifiConnectedWithPartialInfo,
offWifiConnected : OffWifiConnected,
onOffWifiConnectedWithPartialInfo : OnOffWifiConnectedWithPartialInfo,
setWifiList : SetWifiList,
}
function startWifi() {
return new Promise((resolve, reject) => {
uni.startWifi({
success: () => {
console.log('startWifi success');
resolve()
},
fail: () => {
console.log('startWifi fail');
reject()
}
})
})
}
function stopWifi() {
return new Promise((resolve, reject) => {
uni.stopWifi({
success: () => {
console.log('stopWifi success');
resolve()
},
fail: () => {
console.log('stopWifi success');
fail()
}
})
})
}
module.exports = {
startWifi,
stopWifi
}
......@@ -87,6 +87,10 @@ const API = {
* 上传文件
* */
upload: API_BASE_LIEXIN + '/oss/upload',
/**
* 标签补打
* */
latePrint: API_BASE + '/api/label/latePrint',
}
......
......@@ -48,6 +48,24 @@ const request = (url = '', type = 'GET', param = {}, Loading) => {
});
}
/**
* 获取本机局域网IP
*/
const getLocalIpAddress = () => {
uni.getConnectedWifi({
success: res => {
console.log('获取到 WiFi 信息:', res)
const ipRegex = /\d+\.\d+\.\d+\.\d+/
const ipAddress = res.ipAddress.match(ipRegex)[0]
console.log('当前 WiFi ip 地址:', ipAddress)
return ipAddress
},
fail: err => {
console.log('获取 WiFi 信息失败:', err)
return ''
}
})
}
/**
......@@ -78,5 +96,6 @@ const createArray = (length, value) => {
module.exports = {
request,
getPlatform,
createArray
createArray,
getLocalIpAddress,
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment