源文件

This commit is contained in:
gyq
2024-07-02 09:59:38 +08:00
parent 49792356d7
commit 921348766c
532 changed files with 70848 additions and 0 deletions

View File

@@ -0,0 +1,155 @@
<template>
<view>
<view class="tab-header">
<view class="item" :class="{ active: active == 0 }" @click="tabChange(0)">全部</view>
<view class="item" :class="{ active: active == item.id }" v-for="item in tabs" :key="item.id" @click="tabChange(item.id)">
{{ item.name }}
</view>
</view>
<view class="list">
<view class="item" :class="{ active: item.qrcode }" v-for="item in list" :key="item.id" @click="bindCode(item)">
<text class="t1">{{ item.name }}</text>
<text class="t2">{{ item.qrcode ? `重新绑定` : '未绑定' }}</text>
</view>
</view>
<u-empty v-if="!list.length" text="空空如也~"></u-empty>
</view>
</template>
<script>
import { getQueryString } from '@/utils/index.js';
import { tableList, areaList, tableBinding } from '@/api/index.js';
export default {
data() {
return {
active: 0,
tabs: [],
list: []
};
},
onLoad() {
this.areaList();
this.tableList();
},
methods: {
// 绑定
bindCode(item) {
uni.scanCode({
success: (res) => {
let tableCode = getQueryString(decodeURIComponent(res.result), 'code');
uni.showModal({
title: '注意',
content: `确定绑定该桌码吗?`,
success: async (res) => {
if (res.confirm) {
try {
uni.showLoading({
title: '桌码绑定中...',
mask: true
});
await tableBinding({
qrcode: tableCode,
id: item.id
});
uni.hideLoading();
uni.showModal({
title: '注意',
content: '桌码绑定成功',
showCancel: false
});
this.tableList();
} catch (e) {
uni.hideLoading();
}
}
}
});
}
});
},
// 切换
tabChange(id) {
this.active = id;
this.tableList();
},
// 获取区域列表
async areaList() {
try {
const { data } = await areaList();
this.tabs = data;
} catch (e) {
console.log(e);
}
},
// 新版获取店铺桌码信息
async tableList() {
try {
uni.showLoading({
title: '加载中...'
});
const res = await tableList(this.active);
this.list = res.data;
uni.hideLoading();
} catch (e) {
console.log(e);
uni.hideLoading();
}
}
}
};
</script>
<style>
page {
background-color: #fff;
}
</style>
<style scoped lang="scss">
$color: #19be6b;
.tab-header {
display: flex;
padding: 0 14upx;
background-color: #fff;
height: 120upx;
.item {
height: inherit;
padding: 0 28upx;
display: flex;
align-items: center;
font-size: 32upx;
&.active {
color: $color;
}
}
}
.list {
display: grid;
grid-gap: 34upx;
background-color: #fff;
grid-template-columns: 1fr 1fr 1fr 1fr;
padding: 0 34upx 34upx;
.item {
height: 166upx;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
background-color: #f7f7f7;
color: #999;
border-radius: 12upx;
&.active {
background-color: $color;
.t1,
.t2 {
color: #fff;
}
}
.t1 {
font-size: 24upx;
}
.t2 {
font-size: 24upx;
}
}
}
</style>

233
pages/index/index.vue Normal file
View File

@@ -0,0 +1,233 @@
<template>
<view>
<view class="header">
<text class="name">{{ userInfo.account }}</text>
<view class="state-wrap">
<view class="state" :class="[`s${userInfo.status}`]">
<view class="dot"></view>
<text>{{ userInfo.status == 1 ? '正在营业' : '休息中' }}</text>
</view>
</view>
</view>
<!-- 今日收入 -->
<view class="earnings-wrap">
<view class="content">
<view class="item">
<text>今日预计收入/</text>
<text>--</text>
</view>
<view class="item">
<text>有效订单</text>
<text>--</text>
</view>
</view>
</view>
<view class="menu-wrap">
<navigator url="/pages/bind_table/bind_table" hover-class="none" class="item">
<image src="/static/icon_menu1.jpg" mode="aspectFit" class="icon"></image>
<text>绑定桌码</text>
</navigator>
<view class="item" @click="messageHandle">
<image src="/static/icon_menu_notice.png" mode="aspectFit" class="icon"></image>
<text>订阅通知</text>
</view>
<view class="item" @click="logout">
<image src="/static/icon_menu_logout.png" mode="aspectFit" class="icon"></image>
<text>退出登录</text>
</view>
</view>
</view>
</template>
<script>
import { wxlogin } from '@/api/index.js';
export default {
data() {
return {
userInfo: this.useStorage.get('userInfo'),
code: ''
};
},
onLoad() {
if (!this.useStorage.get('token')) {
uni.redirectTo({
url: '/pages/login/login'
});
}
// wx.login({
// success: (res) => {
// console.log(res);
// this.code = res.code;
// }
// });
},
onShow() {
if (this.useStorage.get('token') && !this.useStorage.get('openid')) {
uni.login({
provider: 'weixin',
success: (res) => {
console.log(res);
this.code = res.code;
this.loginHandle();
}
});
}
},
methods: {
async loginHandle() {
try {
const res = await wxlogin({
code: this.code,
shopId: this.useStorage.get('userInfo').shopId
});
this.useStorage.set('openid', res.data.openId);
} catch (e) {
console.log(e);
}
},
// 订阅消息通知
messageHandle() {
let msgId = 'IZ-l9p9yBgcvhRR0uN6cBQPkWJ5i05zyWMkfeCPaAmY';
uni.getSetting({
withSubscriptions: true,
success(res) {
console.log(res, '订阅信息', res.subscriptionsSetting);
if (!res.subscriptionsSetting.mainSwitch) {
uni.openSetting({
success(res) {
console.log('打开设置页', res.authSetting);
}
});
} else {
uni.requestSubscribeMessage({
tmplIds: [msgId],
success(res) {
console.log('requestSubscribeMessage 订阅信息', res);
if (res[msgId] == 'accept') {
// 用户点击确定后
console.log('用户订阅点击确定按钮');
uni.showToast({
title: '订阅成功',
icon: 'none'
});
} else {
console.log('拒绝,不会再弹出弹框 只能去设置页膝盖');
uni.showModal({
title: '您未开启消息订阅',
content: '为了给您提供更好的服务,请您授权消息订阅',
success: (res2) => {
if (res2.confirm) {
uni.openSetting({
success(res) {
console.log('打开设置页', res.authSetting);
}
});
} else {
console.log('决绝');
}
}
});
}
},
fail(errMessage) {
console.log('订阅消息 失败 ', errMessage);
}
});
}
}
});
},
// 退出登录
logout() {
uni.showModal({
title: '注意',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
this.useStorage.clear();
uni.redirectTo({
url: '/pages/login/login'
});
}
}
});
}
}
};
</script>
<style scoped lang="scss">
.header {
display: flex;
align-items: center;
padding: 20upx $paddingSize;
background-color: #fff;
.name {
font-size: 32upx;
font-weight: bold;
color: #000;
}
.state-wrap {
.state {
display: flex;
align-items: center;
padding: 8upx 26upx;
margin-left: $paddingSize;
border-radius: 100upx;
&.s1 {
background-color: #e6f9f3;
.dot {
background-color: #00be7e;
}
}
&.s0 {
background-color: #f5f5f5;
.dot {
background-color: #999;
}
}
.dot {
$size: 20upx;
width: $size;
height: $size;
border-radius: 50%;
margin-right: 20upx;
}
}
}
}
.earnings-wrap {
padding: $paddingSize;
background-color: #fff;
.content {
border-radius: $paddingSize;
padding: $paddingSize;
display: flex;
background-color: #f5f6fa;
.item {
flex: 1;
display: flex;
align-items: center;
flex-direction: column;
gap: $paddingSize;
}
}
}
.menu-wrap {
padding: $paddingSize;
display: flex;
background-color: #fff;
.item {
width: 25%;
display: flex;
flex-direction: column;
align-items: center;
gap: 20upx;
.icon {
$size: 100upx;
width: $size;
height: $size;
}
}
}
</style>

117
pages/login/login.vue Normal file
View File

@@ -0,0 +1,117 @@
<template>
<view class="container">
<view class="title">
<text class="t">欢迎登录</text>
</view>
<view class="form-wrap">
<view class="row">
<u--input
v-model="form.username"
clearable
prefixIcon="account-fill"
prefixIconStyle="font-size: 26px;color:#999;"
placeholder="请输入账号"
border="bottom"
:customStyle="{ height: '100rpx' }"
></u--input>
</view>
<view class="row">
<u--input
v-model="form.password"
type="password"
clearable
prefixIcon="lock-fill"
prefixIconStyle="font-size: 26px;color:#999;"
placeholder="请输入密码"
border="bottom"
:customStyle="{ height: '100rpx' }"
></u--input>
</view>
<view class="row">
<u-button type="primary" class="btn" size="large" :loading="loading" loading-text="登录中..." @click="submintHandle">登录</u-button>
</view>
</view>
</view>
</template>
<script>
import { login } from '@/api';
export default {
data() {
return {
loading: false,
form: {
username: '',
password: ''
}
};
},
methods: {
async submintHandle() {
try {
if (!this.form.username) {
uni.showToast({
title: '请输入用户名',
icon: 'none'
});
return;
}
if (!this.form.password) {
uni.showToast({
title: '请输入密码',
icon: 'none'
});
return;
}
this.loading = true;
const res = await login(this.form);
this.useStorage.set('token', res.data.token);
this.useStorage.set('userInfo', res.data.user);
uni.showToast({
title: '登录成功',
icon: 'success'
});
setTimeout(() => {
uni.redirectTo({
url: '/pages/index/index'
});
}, 1000);
} catch (e) {
this.loading = false;
console.log(e);
}
}
}
};
</script>
<style>
page {
background-color: #fff;
}
.u-button__loading-text {
color: #fff;
}
</style>
<style scoped lang="scss">
.container {
background-color: #fff;
padding: 0 $paddingSize * 3 $paddingSize * 12;
height: 100vh;
display: flex;
flex-direction: column;
justify-content: center;
}
.title {
.t {
font-size: 76upx;
font-weight: bold;
color: #000;
}
}
.form-wrap {
.row {
padding-top: 100upx;
}
}
</style>