使用 taro 重写
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
export default defineAppConfig({
|
||||
pages: [
|
||||
'pages/index/index',
|
||||
'pages/connect-wifi/index',
|
||||
'pages/success/index'
|
||||
],
|
||||
window: {
|
||||
backgroundTextStyle: 'light',
|
||||
navigationBarBackgroundColor: '#fff',
|
||||
navigationBarTitleText: 'WeChat',
|
||||
navigationBarTextStyle: 'black'
|
||||
}
|
||||
})
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { PropsWithChildren } from 'react'
|
||||
import { useLaunch } from '@tarojs/taro'
|
||||
|
||||
import './app.less'
|
||||
|
||||
function App({ children }: PropsWithChildren<any>) {
|
||||
useLaunch(() => {
|
||||
console.log('App launched.')
|
||||
})
|
||||
|
||||
// children 是将要会渲染的页面
|
||||
return children
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default App
|
||||
@@ -0,0 +1,17 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||
<meta content="width=device-width,initial-scale=1,user-scalable=no" name="viewport">
|
||||
<meta name="apple-mobile-web-app-capable" content="yes">
|
||||
<meta name="apple-touch-fullscreen" content="yes">
|
||||
<meta name="format-detection" content="telephone=no,address=no">
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="white">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
|
||||
<title>wifi-assistant</title>
|
||||
<script><%= htmlWebpackPlugin.options.script %></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="app"></div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,3 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '连接 WIFI'
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
.connect-wifi {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
flex-wrap: nowrap;
|
||||
margin-top: 15em;
|
||||
}
|
||||
|
||||
.connect-wifi > .small-text {
|
||||
color: gray;
|
||||
font-size: 14pt;
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { useState } from 'react'
|
||||
import { View, Text, Icon } from '@tarojs/components'
|
||||
import Taro, { useLoad, navigateTo } from '@tarojs/taro'
|
||||
import './index.less'
|
||||
|
||||
|
||||
type wifiInfo = Pick<Taro.connectWifi.Option, 'SSID'| 'password'>
|
||||
|
||||
export default function ConnectWifi () {
|
||||
const [wifiInfo, setWifiInfo] = useState({} as wifiInfo)
|
||||
|
||||
useLoad((options) => {
|
||||
try{
|
||||
const scene = JSON.parse(decodeURIComponent(options.scene)) as wifiInfo
|
||||
setWifiInfo(scene)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
|
||||
Taro.connectWifi({
|
||||
...wifiInfo, maunal: true
|
||||
}).then(()=>{
|
||||
navigateTo({
|
||||
url:'pages/success/index'
|
||||
})
|
||||
}).catch((e) => {
|
||||
console.log(e)
|
||||
})
|
||||
})
|
||||
|
||||
return (
|
||||
<View className='connect-wifi'>
|
||||
<Icon size={60} type='waiting' />
|
||||
<Text>你将连接到 {wifiInfo.SSID || 'WIFI'}</Text>
|
||||
<Text className='small-text'>将跳转至系统设置页面连接 WIFI</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '首页'
|
||||
})
|
||||
@@ -0,0 +1,12 @@
|
||||
import { View, Text } from '@tarojs/components'
|
||||
import './index.less'
|
||||
|
||||
export default function Index () {
|
||||
|
||||
// TODO: 广告
|
||||
return (
|
||||
<View className='index'>
|
||||
<Text>Hello world!</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default definePageConfig({
|
||||
navigationBarTitleText: '连接成功'
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
.success {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
flex-wrap: nowrap;
|
||||
margin-top: 15em;
|
||||
}
|
||||
|
||||
.success > .small-text {
|
||||
color: gray;
|
||||
font-size: 14pt;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import { View, Text, Icon } from '@tarojs/components'
|
||||
import './index.less'
|
||||
|
||||
export default function Success () {
|
||||
|
||||
return (
|
||||
<View className='success'>
|
||||
<Icon size={60} type='success' />
|
||||
<Text>连接成功</Text>
|
||||
<Text className='small-text'>现在可以退出小程序了</Text>
|
||||
</View>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user