diff --git a/api/index.ts b/api/index.ts index e983853..7fd4a59 100644 --- a/api/index.ts +++ b/api/index.ts @@ -6,6 +6,13 @@ import { request } from "./request"; // }) // } +export function fetchLogin(data : {}) { + return request({ + url: '/index/login', + data: data, + method: 'POST' + }) +} @@ -74,3 +81,5 @@ export function fetchRoomOrder(roomId : Number) { data: { roomId: roomId }, }) } + + diff --git a/pages.json b/pages.json index 586ba28..e480eb8 100644 --- a/pages.json +++ b/pages.json @@ -40,6 +40,13 @@ "enablePullDownRefresh": false } }, + { + "path": "pages/login/index", + "style": { + "navigationStyle": "custom", + "navigationBarTitleText": "登陆" + } + }, { "path": "pages/index/orderAdd", "style": { @@ -149,77 +156,72 @@ // "navigationStyle": "custom" // } // }, - { - "path": "pages/login/index", - "style": { - "navigationBarTitleText": "授权登录" - } - }, - { - "path": "pages/login/phoneAuthorization", - "style": { - "navigationBarTitleText": "授权手机号" - } - }, + + // { + // "path": "pages/login/phoneAuthorization", + // "style": { + // "navigationBarTitleText": "授权手机号" + // } + // }, // { // "path": "pages/control/goods/index", // "style": { // "navigationBarTitleText": "商品管理" // } // }, - { - "path": "pages/config/store", - "style": { - "navigationBarTitleText": "商城配置" - } - }, - { - "path": "pages/config/price", - "style": { - "navigationBarTitleText": "价格调整", - "enablePullDownRefresh": false - } - }, - { - "path": "pages/config/goodsList", - "style": { - "navigationBarTitleText": "商品管理", - "enablePullDownRefresh": false - } - }, - { - "path": "pages/config/goodsAdd", - "style": { - "navigationBarTitleText": "新增商品", - "enablePullDownRefresh": false - } - }, - { - "path": "pages/config/goodsEdit", - "style": { - "navigationBarTitleText": "编辑商品", - "enablePullDownRefresh": false - } - }, - { - "path": "pages/config/goodsDetail", - "style": { - "navigationBarTitleText": "店铺商品详情", - "enablePullDownRefresh": false - } - }, - { - "path": "pages/config/shopOrder/index", - "style": { - "navigationBarTitleText": "店铺订单" - } - }, - { - "path": "pages/config/shopOrder/detail", - "style": { - "navigationBarTitleText": "店铺订单-详情" - } - } + // { + // "path": "pages/config/store", + // "style": { + // "navigationBarTitleText": "商城配置" + // } + // }, + // { + // "path": "pages/config/price", + // "style": { + // "navigationBarTitleText": "价格调整", + // "enablePullDownRefresh": false + // } + // }, + // { + // "path": "pages/config/goodsList", + // "style": { + // "navigationBarTitleText": "商品管理", + // "enablePullDownRefresh": false + // } + // }, + // { + // "path": "pages/config/goodsAdd", + // "style": { + // "navigationBarTitleText": "新增商品", + // "enablePullDownRefresh": false + // } + // }, + // { + // "path": "pages/config/goodsEdit", + // "style": { + // "navigationBarTitleText": "编辑商品", + // "enablePullDownRefresh": false + // } + // }, + // { + // "path": "pages/config/goodsDetail", + // "style": { + // "navigationBarTitleText": "店铺商品详情", + // "enablePullDownRefresh": false + // } + // }, + // { + // "path": "pages/config/shopOrder/index", + // "style": { + // "navigationBarTitleText": "店铺订单" + // } + // }, + // { + // "path": "pages/config/shopOrder/detail", + // "style": { + // "navigationBarTitleText": "店铺订单-详情" + // } + // } // { // "path": "pages/control/parts/index", // "style": { @@ -247,7 +249,7 @@ ], "globalStyle": { "navigationBarTextStyle": "black", - "navigationBarTitleText": "远阳数码", + "navigationBarTitleText": "茶麻古道", "navigationBarBackgroundColor": "#fff", "backgroundTextStyle": "dark", "backgroundColor": "#F2F3F5", diff --git a/pages/index/index.vue b/pages/index/index.vue index bbd1663..194cd87 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -1,5 +1,5 @@ @@ -96,11 +112,61 @@ import { fetchRooms, fetchBooking, - fetchUnBooking + fetchUnBooking, + fetchLogin, } from '@/api/index'; import { navigateTo, } from '@/utils/helper' + + // 响应式变量,用于控制是否显示列表或提示登录 + const isLoggedIn = ref(false); + + + + // 响应式数据 + const username = ref(''); + const password = ref(''); + + // 登录方法 + const handleLogin = () => { + if (username.value === '') { + uni.showToast({ + title: '请输入用户名', + icon: 'none', + }); + return; + } + if (password.value === '') { + uni.showToast({ + title: '请输入密码', + icon: 'none', + }); + return; + } + fetchLogin({ + user_name: username.value, + password: password.value + }).then(res => { + console.log(res); + uni.setStorageSync('token', res.token) + uni.setStorageSync('uid', res.user.user_id) + uni.setStorageSync('username', res.user.user_name) + uni.setStorageSync('role', res.user.role.value) + isLoggedIn.value = true + // 登录操作(模拟成功) + uni.showToast({ + title: '登录成功', + icon: 'success', + }); + // rooms.value = res; + }) + + + }; + + + const form = reactive({ room_id: 0, tel: '', @@ -131,21 +197,21 @@ return { 'background-color': backgroundColor, }; - } - - const visibleInfoPopup = ref(false) + } + + const visibleInfoPopup = ref(false) const onShowInfoPopup = (room) => { console.log("----", room); Object.assign(tempRoom, room) visibleInfoPopup.value = true - } - const onCloseInfoPopup = () => { - Object.assign(tempRoom, {}) - visibleInfoPopup.value = false - console.log("关闭"); - }; - - + } + const onCloseInfoPopup = () => { + Object.assign(tempRoom, {}) + visibleInfoPopup.value = false + console.log("关闭"); + }; + + const visiblePopup = ref(false) const tempRoom = reactive({}) const onBooking = (room) => { @@ -163,10 +229,11 @@ }) visiblePopup.value = false console.log("关闭"); - }; - + }; + + // 获取房间 const getRooms = () => { console.log("房间"); fetchRooms().then(res => { @@ -203,14 +270,27 @@ const init = () => { console.log('init'); + uni.hideTabBar() + checkLogin() getRooms() } onShow(() => { console.log("onshow---"); + uni.hideTabBar() + checkLogin() getRooms() }); + + const checkLogin = () => { + let token = uni.getStorageSync('token'); + console.log("token", token); + if (token) { + uni.showTabBar() + isLoggedIn.value = true; + } + } onMounted(() => { init(); }) @@ -319,22 +399,52 @@ font-size: 28rpx; font-weight: 400; text-align: center; - } - - .room-info { - text-align: left; - padding: 20rpx 20rpx; - color: #666; - width: 100%; - // min-height: 160rpx; - box-sizing: border-box; - - .room-id { - font-size: 28rpx; - } - - .remark { - font-size: 26rpx; - } + } + + .room-info { + text-align: left; + padding: 20rpx 20rpx; + color: #666; + width: 100%; + // min-height: 160rpx; + box-sizing: border-box; + + .room-id { + font-size: 28rpx; + } + + .remark { + font-size: 26rpx; + } + } + + + .login-page { + display: flex; + // justify-content: center; + align-items: center; + flex-direction: column; + height: 100vh; + } + + .login-title { + margin-top: 240rpx; + + margin-bottom: 40rpx; + font-size: 32rpx; + color: #333; + font-weight: bold; + } + + .title-text { + font-size: 36rpx; + color: #ff6600; + text-align: center; + } + + .login-container { + width: 80%; + // max-width: 700rpx; + padding: 40rpx; } \ No newline at end of file diff --git a/pages/login/index.vue b/pages/login/index.vue index d448b3c..2ce5245 100644 --- a/pages/login/index.vue +++ b/pages/login/index.vue @@ -1,115 +1,119 @@ -