购物商城,便利店商城

  项目源码获取方式放在文章末尾

一、技术栈

基于nodejs+vue 便利店商城,前后端分离项目,角色分为管理员和用户

前端:vue框架

后端:nodejs express框架,数据库:mysql。

二、系统功能展示

管理员功能

管理员功能包含用户管理,商品管理,类别管理,订单管理等功能。

0b052f8d65c14564b363c81265934a0f.png

061c1b793453439b9bbdcbebcbc95ab5.png

用户功能

用户功能首页

用户在该页面可以查看和搜索商品。

b97a54580e7d4a44aa65357e4177432b.png

81336fc01b31451d852a5cb660011f42.png

商品详情页面

e4a4710d888b43e291862d0f412e077c.png

购物车页面 

72fe12e3b1094f39874d5b0fab2ec64c.png

 

个人信息页面

fecf4010cd2841caa287ea1bb9c3ea01.png

 

三、部分代码

用户登录

exports.register = (req, res) => {
  const userInfo = req.body;
  if (!userInfo.username) {
    return res.response("用户名不能为空");
  };
  const performRegistration = () => {
    const sql = "insert into user set ?";
    const min = 1000;
    const max = 9999;
    const randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
    const nickname = 'pet' + randomNum;
    const avatar = '/public/avatar.png'
    const created = dayjs().format("YYYY-MM-DD HH:mm:ss");
    database.query(
      sql,
      {
        ...userInfo,
        nickname,
        avatar,
        created,
      },
      function (err, results) {
        if (err) return res.response(err);
        login()
      }
    );
  };
  const login = () => {
    const sql1 = "select * from user where username=?";
    database.query(sql1, [userInfo.username], function (err, results) {
      if (err) {
        return res.response(err);
      };
      // 如果查询到用户,则返回用户信息
      if (results.length > 0) {
        const { id, username } = results[0];
        let user = {
          id,
          username,
        };
        const token = jwt.sign(user, config.jwtSecretKey, {
          expiresIn: config.expiresIn, // token 有效期为 10 个小时
        });
        setTimeout(() => {
          res.send({
            code: 0,
            message: "登录成功!",
            result: {
              token: "Bearer " + token,
              userInfo: results[0],
            },
          });
        }, 100);
        return
      };
      // 如果未查询到用户,执行注册逻辑
      performRegistration();
    });
  }
  login();
};

文件上传

const multer = require("multer");
const path = require("path"); //
const resolve = (dir) => {
  return path.join(__dirname, "./", dir);
};
let temp = multer.diskStorage({

  destination: function (req, file, cb) {
    if (file.mimetype.match('image.*') || file.mimetype.match('video.*')) {
      cb(null, resolve("../public/images"));
    } else {
      cb({ error: "Mime type not supported" });
    }
  },

  filename: function (req, file, cb) {
    let fileFormat = file.originalname.split(".");
    const min = 1000;
    const max = 9999;
    const randomNum = Math.floor(Math.random() * (max - min + 1)) + min;
    cb(null, new Date().getTime() + "" + randomNum + "." + fileFormat[fileFormat.length - 1]);
  },
});

const multerConfig = multer({
  storage: temp,
});
module.exports = multerConfig;

四、获取源码

关注,点赞,私信我吧

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值