当前位置:实例文章 » HTML/CSS实例» [文章]基于nodejs+vue微信小程序加油站服务管理系统

基于nodejs+vue微信小程序加油站服务管理系统

发布人:shili8 发布时间:2025-03-06 17:30 阅读次数:0

**基于Node.js + Vue 的微信小程序加油站服务管理系统**

**系统概述**

本系统是为加油站服务提供的一套管理系统,主要功能包括用户管理、加油记录管理、订单管理等。系统使用 Node.js 和 Vue 构建,前端采用微信小程序开发。

**系统架构**

系统架构如下:

* **后端**: Node.js + Express.js* **前端**: 微信小程序 (Vue)
* **数据库**: MySQL**系统功能**

1. **用户管理**
* 用户注册和登录 * 用户信息管理(修改、删除)
2. **加油记录管理**
* 加油记录添加和编辑 * 加油记录列表展示3. **订单管理**
* 订单添加和编辑 * 订单列表展示**系统实现**

### 后端(Node.js + Express.js)

#### 用户管理

javascript// userController.jsconst express = require('express');
const router = express.Router();
const User = require('../models/User');

router.post('/register', async (req, res) => {
 try {
 const user = new User(req.body);
 await user.save();
 res.json({ message: 'User registered successfully' });
 } catch (error) {
 res.status(400).json({ message: error.message });
 }
});

router.post('/login', async (req, res) => {
 try {
 const user = await User.findOne({ username: req.body.username });
 if (!user) return res.status(401).json({ message: 'Invalid credentials' });
 const isValidPassword = await user.comparePassword(req.body.password);
 if (!isValidPassword) return res.status(401).json({ message: 'Invalid credentials' });
 const token = jwt.sign({ userId: user._id }, process.env.SECRET_KEY, { expiresIn: '1h' });
 res.json({ token });
 } catch (error) {
 res.status(400).json({ message: error.message });
 }
});


#### 加油记录管理
javascript// fuelRecordController.jsconst express = require('express');
const router = express.Router();
const FuelRecord = require('../models/FuelRecord');

router.post('/add', async (req, res) => {
 try {
 const fuelRecord = new FuelRecord(req.body);
 await fuelRecord.save();
 res.json({ message: 'Fuel record added successfully' });
 } catch (error) {
 res.status(400).json({ message: error.message });
 }
});

router.get('/list', async (req, res) => {
 try {
 const fuelRecords = await FuelRecord.find().sort({ createdAt: -1 }).exec();
 res.json(fuelRecords);
 } catch (error) {
 res.status(400).json({ message: error.message });
 }
});


#### 订单管理
javascript// orderController.jsconst express = require('express');
const router = express.Router();
const Order = require('../models/Order');

router.post('/add', async (req, res) => {
 try {
 const order = new Order(req.body);
 await order.save();
 res.json({ message: 'Order added successfully' });
 } catch (error) {
 res.status(400).json({ message: error.message });
 }
});

router.get('/list', async (req, res) => {
 try {
 const orders = await Order.find().sort({ createdAt: -1 }).exec();
 res.json(orders);
 } catch (error) {
 res.status(400).json({ message: error.message });
 }
});


### 前端(微信小程序)

#### 用户管理
javascript// user.jsPage({
 data: {
 username: '',
 password: ''
 },

 handleRegister() {
 wx.cloud.callFunction({
 name: 'user',
 data: {
 action: 'register',
 username: this.data.username,
 password: this.data.password }
 }).then(res => {
 console.log(res);
 wx.showToast({ title: '注册成功' });
 }).catch(error => {
 console.error(error);
 wx.showToast({ title: '注册失败', icon: 'none' });
 });
 },

 handleLogin() {
 wx.cloud.callFunction({
 name: 'user',
 data: {
 action: 'login',
 username: this.data.username,
 password: this.data.password }
 }).then(res => {
 console.log(res);
 wx.setStorageSync('token', res.result.token);
 wx.showToast({ title: '登录成功' });
 }).catch(error => {
 console.error(error);
 wx.showToast({ title: '登录失败', icon: 'none' });
 });
 }
});


#### 加油记录管理
javascript// fuelRecord.jsPage({
 data: {
 fuelRecords: []
 },

 handleAdd() {
 wx.cloud.callFunction({
 name: 'fuelRecord',
 data: {
 action: 'add',
 ...this.data.fuelRecord }
 }).then(res => {
 console.log(res);
 this.setData({ fuelRecords: [...this.data.fuelRecords, res.result] });
 wx.showToast({ title: '添加成功' });
 }).catch(error => {
 console.error(error);
 wx.showToast({ title: '添加失败', icon: 'none' });
 });
 },

 handleList() {
 wx.cloud.callFunction({
 name: 'fuelRecord',
 data: { action: 'list' }
 }).then(res => {
 console.log(res);
 this.setData({ fuelRecords: res.result });
 }).catch(error => {
 console.error(error);
 wx.showToast({ title: '获取列表失败', icon: 'none' });
 });
 }
});


#### 订单管理
javascript// order.jsPage({
 data: {
 orders: []
 },

 handleAdd() {
 wx.cloud.callFunction({
 name: 'order',
 data: {
 action: 'add',
 ...this.data.order }
 }).then(res => {
 console.log(res);
 this.setData({ orders: [...this.data.orders, res.result] });
 wx.showToast({ title: '添加成功' });
 }).catch(error => {
 console.error(error);
 wx.showToast({ title: '添加失败', icon: 'none' });
 });
 },

 handleList() {
 wx.cloud.callFunction({
 name: 'order',
 data: { action: 'list' }
 }).then(res => {
 console.log(res);
 this.setData({ orders: res.result });
 }).catch(error => {
 console.error(error);
 wx.showToast({ title: '获取列表失败', icon: 'none' });
 });
 }
});


**注意**

* 这是一个基本的示例,需要根据实际需求进行调整和扩展。
* 在生产环境中,请确保使用 HTTPS 和正确配置云函数。
* 如果您有任何问题或需要进一步帮助,请随时联系我。

其他信息

其他资源

Top