|
@@ -23,15 +23,15 @@
|
|
|
<view class="step-item">
|
|
<view class="step-item">
|
|
|
<view class="tag">step1</view>
|
|
<view class="tag">step1</view>
|
|
|
<view class="icon">
|
|
<view class="icon">
|
|
|
- <i class="iconfont icon-shangchuanwenjian"></i>
|
|
|
|
|
|
|
+ <i class="iconfont icon-shoujiWiFi"></i>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="label">先连接"maoer-hub"开头的WIFI</view>
|
|
|
|
|
|
|
+ <view class="label">先连接"maoer-hub"开头的WiFi</view>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="step-link">···</view>
|
|
<view class="step-link">···</view>
|
|
|
<view class="step-item">
|
|
<view class="step-item">
|
|
|
<view class="tag">step2</view>
|
|
<view class="tag">step2</view>
|
|
|
<view class="icon">
|
|
<view class="icon">
|
|
|
- <i class="iconfont icon-dayinshezhi"></i>
|
|
|
|
|
|
|
+ <i class="iconfont icon-internet"></i>
|
|
|
</view>
|
|
</view>
|
|
|
<view class="label">开始配网</view>
|
|
<view class="label">开始配网</view>
|
|
|
</view>
|
|
</view>
|
|
@@ -39,9 +39,9 @@
|
|
|
<view class="step-item">
|
|
<view class="step-item">
|
|
|
<view class="tag">step3</view>
|
|
<view class="tag">step3</view>
|
|
|
<view class="icon">
|
|
<view class="icon">
|
|
|
- <i class="iconfont icon-dayinwancheng"></i>
|
|
|
|
|
|
|
+ <i class="iconfont icon-online"></i>
|
|
|
</view>
|
|
</view>
|
|
|
- <view class="label">选择链接WIFI</view>
|
|
|
|
|
|
|
+ <view class="label">选择连接WiFi</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
|
</view>
|
|
</view>
|
|
@@ -49,34 +49,34 @@
|
|
|
<view class="opt-contain">
|
|
<view class="opt-contain">
|
|
|
<view class="btn" @click="getConnectedWifi()">开始配网</view>
|
|
<view class="btn" @click="getConnectedWifi()">开始配网</view>
|
|
|
<i class="iconfont icon-xiayibu icon-down"></i>
|
|
<i class="iconfont icon-xiayibu icon-down"></i>
|
|
|
- <view class="tips">配网成功后再选择WIFI</view>
|
|
|
|
|
|
|
+ <view class="tips">配网成功后再选择WiFi</view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
|
<view class="form-contain">
|
|
<view class="form-contain">
|
|
|
- <wd-form ref="form" :model="formData">
|
|
|
|
|
|
|
+ <wd-form ref="form" :model="formData" custom-class="my-form">
|
|
|
<wd-cell-group custom-class="form-group" border>
|
|
<wd-cell-group custom-class="form-group" border>
|
|
|
<wd-select-picker
|
|
<wd-select-picker
|
|
|
v-model="formData.ssid"
|
|
v-model="formData.ssid"
|
|
|
- label="无线名称"
|
|
|
|
|
|
|
+ label="WiFi名称"
|
|
|
label-width="100px"
|
|
label-width="100px"
|
|
|
prop="ssid"
|
|
prop="ssid"
|
|
|
type="radio"
|
|
type="radio"
|
|
|
filterable
|
|
filterable
|
|
|
- placeholder="请选择家里的无线名称"
|
|
|
|
|
|
|
+ placeholder="请选择WiFi"
|
|
|
:columns="wifiList"
|
|
:columns="wifiList"
|
|
|
value-key="ssid"
|
|
value-key="ssid"
|
|
|
label-key="ssid"
|
|
label-key="ssid"
|
|
|
:loading="loading"
|
|
:loading="loading"
|
|
|
:max="1"
|
|
:max="1"
|
|
|
:show-confirm="false"
|
|
:show-confirm="false"
|
|
|
- :rules="[{ required: true, message: '请选择家里的无线名称' }]"
|
|
|
|
|
|
|
+ :rules="[{ required: true, message: '请选择WiFi' }]"
|
|
|
/>
|
|
/>
|
|
|
<wd-input
|
|
<wd-input
|
|
|
v-model="formData.pwd"
|
|
v-model="formData.pwd"
|
|
|
- label="无线密码"
|
|
|
|
|
|
|
+ label="WiFi密码"
|
|
|
label-width="100px"
|
|
label-width="100px"
|
|
|
prop="pwd"
|
|
prop="pwd"
|
|
|
- placeholder="请输入家里的无线密码"
|
|
|
|
|
|
|
+ placeholder="请输入WiFi密码"
|
|
|
clearable
|
|
clearable
|
|
|
show-password
|
|
show-password
|
|
|
:rules="[{ required: true, pattern: /^.{8,}$/, message: '请输入不少于8位无线密码' }]"
|
|
:rules="[{ required: true, pattern: /^.{8,}$/, message: '请输入不少于8位无线密码' }]"
|
|
@@ -84,75 +84,40 @@
|
|
|
</wd-cell-group>
|
|
</wd-cell-group>
|
|
|
|
|
|
|
|
<view class="form-footer">
|
|
<view class="form-footer">
|
|
|
- <wd-button type="primary" size="large" :disabled="loading" @click="handleSubmit()" block>提交</wd-button>
|
|
|
|
|
|
|
+ <wd-button type="primary" size="large" block :disabled="loading" @click="handleSubmit()">确认</wd-button>
|
|
|
</view>
|
|
</view>
|
|
|
</wd-form>
|
|
</wd-form>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
|
- <!-- <view class="form-title">
|
|
|
|
|
- <view>配网步骤</view>
|
|
|
|
|
- </view>
|
|
|
|
|
- <view class="tips-box">
|
|
|
|
|
- <wd-img :src="deviceImg" width="100" mode="widthFix"></wd-img>
|
|
|
|
|
- <view class="check-box">
|
|
|
|
|
- <view class="check-result">{{ checkResult }}</view>
|
|
|
|
|
- <view v-if="currentWifi" class="check-result">{{ `设备当前连接WiFi: ${currentWifi}` }}</view>
|
|
|
|
|
- <wd-button @click="getConnectedWifi()">重新检查</wd-button>
|
|
|
|
|
|
|
+ <wd-message-box selector="wd-message-box-slot">
|
|
|
|
|
+ <view class="message-contain">
|
|
|
|
|
+ <template v-if="connectFlag">
|
|
|
|
|
+ <i class="iconfont icon-online"></i>
|
|
|
|
|
+ <view class="result color-success">WiFi已经连接</view>
|
|
|
|
|
+ <view class="tips">助手已经连接到网络,你可以去打印了。</view>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ <template v-else>
|
|
|
|
|
+ <i class="iconfont icon-offline"></i>
|
|
|
|
|
+ <view class="result color-danger">WiFi连接失败</view>
|
|
|
|
|
+ </template>
|
|
|
</view>
|
|
</view>
|
|
|
- <view v-if="!checkWiFiFlag">{{ `请先连接以 "${targetWifi}" 开头的WiFi` }}</view>
|
|
|
|
|
- </view>
|
|
|
|
|
-
|
|
|
|
|
- <view class="form-title">
|
|
|
|
|
- <view>家庭路由器信息</view>
|
|
|
|
|
- <view class="opt-item" @click="getWifiList()">
|
|
|
|
|
- <wd-icon name="refresh" size="30rpx"></wd-icon>
|
|
|
|
|
- <text>刷新无线列表</text>
|
|
|
|
|
- </view>
|
|
|
|
|
- </view>
|
|
|
|
|
- <wd-form ref="form" :model="formData">
|
|
|
|
|
- <wd-cell-group custom-class="form-group" border>
|
|
|
|
|
- <wd-select-picker
|
|
|
|
|
- v-model="formData.ssid"
|
|
|
|
|
- label="无线名称"
|
|
|
|
|
- label-width="100px"
|
|
|
|
|
- prop="ssid"
|
|
|
|
|
- type="radio"
|
|
|
|
|
- filterable
|
|
|
|
|
- placeholder="请选择家里的无线名称"
|
|
|
|
|
- :columns="wifiList"
|
|
|
|
|
- value-key="ssid"
|
|
|
|
|
- label-key="ssid"
|
|
|
|
|
- :loading="loading"
|
|
|
|
|
- :max="1"
|
|
|
|
|
- :show-confirm="false"
|
|
|
|
|
- :rules="[{ required: true, message: '请选择家里的无线名称' }]"
|
|
|
|
|
- />
|
|
|
|
|
- <wd-input
|
|
|
|
|
- v-model="formData.pwd"
|
|
|
|
|
- label="无线密码"
|
|
|
|
|
- label-width="100px"
|
|
|
|
|
- prop="pwd"
|
|
|
|
|
- placeholder="请输入家里的无线密码"
|
|
|
|
|
- clearable
|
|
|
|
|
- show-password
|
|
|
|
|
- :rules="[{ required: true, pattern: /^.{8,}$/, message: '请输入不少于8位无线密码' }]"
|
|
|
|
|
- />
|
|
|
|
|
- </wd-cell-group>
|
|
|
|
|
-
|
|
|
|
|
- <view class="form-footer">
|
|
|
|
|
- <wd-button type="primary" size="large" :disabled="loading" @click="handleSubmit()" block>提交</wd-button>
|
|
|
|
|
- </view>
|
|
|
|
|
- </wd-form> -->
|
|
|
|
|
|
|
+ </wd-message-box>
|
|
|
</view>
|
|
</view>
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
import { testConnect, getWifiStatus, getWifis, connectWifi } from '@/service/api/index'
|
|
import { testConnect, getWifiStatus, getWifis, connectWifi } from '@/service/api/index'
|
|
|
-import { useToast } from 'wot-design-uni'
|
|
|
|
|
|
|
+import { useToast, useMessage } from 'wot-design-uni'
|
|
|
|
|
+
|
|
|
|
|
+defineOptions({
|
|
|
|
|
+ name: 'Connect',
|
|
|
|
|
+ styleIsolation: 'shared'
|
|
|
|
|
+})
|
|
|
|
|
|
|
|
const loading = ref(false)
|
|
const loading = ref(false)
|
|
|
-const deviceImg = ref('/static/images/device.png')
|
|
|
|
|
const toast = useToast()
|
|
const toast = useToast()
|
|
|
|
|
+const message = useMessage()
|
|
|
|
|
+const messageSlot = useMessage("wd-message-box-slot")
|
|
|
const targetWifi = "maoer-hub"
|
|
const targetWifi = "maoer-hub"
|
|
|
const checkWiFiFlag = ref(false)
|
|
const checkWiFiFlag = ref(false)
|
|
|
const checkIPFlag = ref(false)
|
|
const checkIPFlag = ref(false)
|
|
@@ -167,18 +132,14 @@ const formData: any = ref({
|
|
|
pwd: "",
|
|
pwd: "",
|
|
|
})
|
|
})
|
|
|
const wifiList: any = ref([])
|
|
const wifiList: any = ref([])
|
|
|
-// 检查结果
|
|
|
|
|
-const checkResult = computed(() => {
|
|
|
|
|
- return checkWiFiFlag.value ? (checkIPFlag.value ? "已检测到设备" : "未检测到设备") : "未连接指定WiFi"
|
|
|
|
|
-})
|
|
|
|
|
|
|
+const connectFlag = ref(false)
|
|
|
|
|
|
|
|
// 检查手机wifi连接是否正确, 匹配前缀
|
|
// 检查手机wifi连接是否正确, 匹配前缀
|
|
|
function checkWifi() {
|
|
function checkWifi() {
|
|
|
if (wifiInfo.value.SSID.startsWith(targetWifi)) {
|
|
if (wifiInfo.value.SSID.startsWith(targetWifi)) {
|
|
|
checkWiFiFlag.value = true
|
|
checkWiFiFlag.value = true
|
|
|
- toast.success('您已连接指定WiFi!')
|
|
|
|
|
} else {
|
|
} else {
|
|
|
- toast.warning(`请先连接以 "${targetWifi}" 开头的WiFi`)
|
|
|
|
|
|
|
+ message.alert(`请先连接以 "${targetWifi}" 开头的WiFi`)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -194,11 +155,19 @@ function getConnectedWifi(isFirst = false) {
|
|
|
if (checkWiFiFlag.value) checkIP(isFirst)
|
|
if (checkWiFiFlag.value) checkIP(isFirst)
|
|
|
},
|
|
},
|
|
|
fail: (err) => {
|
|
fail: (err) => {
|
|
|
- toast.error('获取WiFi信息失败')
|
|
|
|
|
|
|
+ message.alert(`获取WiFi信息失败,请先已开启手机WLAN,并连接以 "${targetWifi}" 开头的WiFi`)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}, 1000)
|
|
}, 1000)
|
|
|
- }).catch((err)=> {})
|
|
|
|
|
|
|
+ }).catch((err)=> {
|
|
|
|
|
+ let tips = "初始化wifi模块失败, 请重试"
|
|
|
|
|
+ switch (err.errMsg) {
|
|
|
|
|
+ case "startWifi:fail 开发者工具暂时不支持此 API 调试,请使用真机进行开发":
|
|
|
|
|
+ tips = "开发者工具暂时不支持此 API 调试,请使用真机进行开发"
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ message.alert(tips)
|
|
|
|
|
+ })
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 局域网通信: 检查IP地址是否请求成功
|
|
// 局域网通信: 检查IP地址是否请求成功
|
|
@@ -208,10 +177,11 @@ function checkIP(isFirst: boolean = false) {
|
|
|
checkIPFlag.value = true
|
|
checkIPFlag.value = true
|
|
|
getDeviceWifiStatus()
|
|
getDeviceWifiStatus()
|
|
|
if (isFirst) getWifiList()
|
|
if (isFirst) getWifiList()
|
|
|
|
|
+ message.alert("已检测到设备,请选择连接WiFi以及输入密码")
|
|
|
}).catch((err)=> {
|
|
}).catch((err)=> {
|
|
|
checkIPFlag.value = false
|
|
checkIPFlag.value = false
|
|
|
wifiList.value = []
|
|
wifiList.value = []
|
|
|
- toast.warning('未检测到设备')
|
|
|
|
|
|
|
+ message.alert("已连接指定WiFi,但未检测到设备,请稍后重试")
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -250,12 +220,16 @@ function handleSubmit() {
|
|
|
title: '正在提交...'
|
|
title: '正在提交...'
|
|
|
});
|
|
});
|
|
|
connectWifi(formData.value).then((res: any) => {
|
|
connectWifi(formData.value).then((res: any) => {
|
|
|
- console.log('res: ', res);
|
|
|
|
|
- toast.success('连接成功')
|
|
|
|
|
currentWifi.value = res.body || ""
|
|
currentWifi.value = res.body || ""
|
|
|
|
|
+ connectFlag.value = true
|
|
|
|
|
+ messageSlot.alert("").then(() => {
|
|
|
|
|
+ uni.reLaunch({
|
|
|
|
|
+ url: `/pages/index/index`,
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
}).catch((err) => {
|
|
}).catch((err) => {
|
|
|
- console.log('err: ', err);
|
|
|
|
|
- toast.error('连接失败')
|
|
|
|
|
|
|
+ connectFlag.value = false
|
|
|
|
|
+ messageSlot.alert("")
|
|
|
getDeviceWifiStatus()
|
|
getDeviceWifiStatus()
|
|
|
})
|
|
})
|
|
|
.finally(() => {
|
|
.finally(() => {
|
|
@@ -276,7 +250,14 @@ onLoad(() => {
|
|
|
background-color: #fff;
|
|
background-color: #fff;
|
|
|
}
|
|
}
|
|
|
.guide-contain {
|
|
.guide-contain {
|
|
|
- margin-top: 20rpx;
|
|
|
|
|
|
|
+ margin-top: 30rpx;
|
|
|
|
|
+ .step-contain {
|
|
|
|
|
+ .step-item:first-of-type {
|
|
|
|
|
+ .label {
|
|
|
|
|
+ bottom: 30rpx;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
.opt-contain {
|
|
.opt-contain {
|
|
|
color: #666;
|
|
color: #666;
|
|
@@ -292,17 +273,12 @@ onLoad(() => {
|
|
|
margin-top: 20rpx;
|
|
margin-top: 20rpx;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-// .tips-box {
|
|
|
|
|
-// width: calc(100% - 60rpx);
|
|
|
|
|
-// padding: 40rpx 30rpx;
|
|
|
|
|
-// text-align: center;
|
|
|
|
|
-// background-color: #fff;
|
|
|
|
|
-// border-radius: 16rpx;
|
|
|
|
|
-// }
|
|
|
|
|
-// .check-box {
|
|
|
|
|
-// margin: 40rpx 0;
|
|
|
|
|
-// .check-result {
|
|
|
|
|
-// margin-bottom: 30rpx;
|
|
|
|
|
|
|
+// 写在公共样式中
|
|
|
|
|
+// :deep(.form-contain) {
|
|
|
|
|
+// .wd-select-picker__cell,
|
|
|
|
|
+// .wd-input,
|
|
|
|
|
+// .wd-input__icon {
|
|
|
|
|
+// background-color: rgba(15, 95, 254, 0.05) !important;
|
|
|
// }
|
|
// }
|
|
|
// }
|
|
// }
|
|
|
</style>
|
|
</style>
|