# VueCms
**Repository Path**: MagicWingMI/VueCms
## Basic Information
- **Project Name**: VueCms
- **Description**: 一个内容管理系统的手机移动Web,前端基于vue.js,mintUi和mui代码片段,后端基于Node.js和MySQL,包管理基于npm,用webpack工具打包
- **Primary Language**: JavaScript
- **License**: MIT
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 3
- **Forks**: 0
- **Created**: 2020-06-23
- **Last Updated**: 2021-08-23
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# VueCms
## 项目描述
### 项目背景
+ 手机Web
+ CMS内容管理系统
+ 学习vue.js和webpack的一个大综合性的项目,真的学到了很多,受益匪浅,记录下来!!!
#### 具有功能
1、新闻咨询
2、图片分享
3、商品购买
### 技术要点
#### 前端
1、基于 vue.js 框架
2、使用 MUI HTML代码片段
3、使用 Mint Ui 的vue组件
#### 后端
1、基于Node.js的服务器端,运行与3000端口 ,进行了允许跨域的设置
2、基于MySQL的数据访问和存储
#### 打包工具和包管理
1、基于npm的包管理工具
2、基于webpack来进行打包
## 项目运行环境搭建
### MySQL搭建
+ 安装MySQL
+ 运行vuecms.sql 文件机型数据库及数据的初始化
### 后端搭建
+ 导入VueCmsApi 至工作空间
+ 安装 npm,node
+ 在文件夹根路径 运行命令 npm i
+ 修稿models文件夹下的 mysql.js 文件中的关于连接MySQL数据库的用户名和密码
+ 运行node app.js
### 前端搭建
+ 导入VueCms 至工作空间
+ 安装 npm,
+ 在文件夹根路径 运行命令 npm i
+ 进行调试 npm run dev或者webpack
+ 如果是npm run dev 则打开localhost:8080
+ 如果是webpack 则直接运行 dist中的index.html
## 项目预览
### 主页

### 新闻列表

### 新闻详情

### 图片分享

### 商品列表

### 商品详情

### 购物车

## 接口
> ```
> // 已经在main.js中已经设置了根路径
> Vue.http.options.root = 'http://localhost:3000/';
> ```
### 请求`home.vue`主页轮播图
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| -------------------------------------- | ---------------------------------- | ---- | ---- | ------------------ |
| http://localhost:3000/api/getListLunBo | status:0(正确)
status:1(错误) | GET | 无 | result.body.result |
#### 列子
```
this.$http.get("http://localhost:3000/api/getListLunBo").then(result => {
if (result.body.status === 0 ) {
this.lunBoList = result.body.result
} else {
Toast({
message: '轮播图数据加载数百',
position: 'bottom',
duration: 1500
});
}
})
```
### 请求新闻列表
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| -------------- | ---------------------------------- | ---- | ---- | ------------------ |
| api/getNewList | status:0(正确)
status:1(错误) | GET | 无 | result.body.result |
#### 例子
```javascript
this.$http.get('api/getNewList').then(result =>{
if (result.body.status === 0) {
this.newList = result.body.result
} else {
Toast({
message: '轮播图数据加载失败',
position: 'bottom',
duration: 1500
});
}
console.log(this.newList);
})
```
### 请求评论列表
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| ---------------- | ---------------------------------- | ---- | ------------------------------------- | ------------------ |
| /api/getcomments | status:0(正确)
status:1(错误) | GET | {id:请求页的id,
pageindex:页码} | result.body.result |
#### 列子
```javascript
// 注意: 请求的时候带上父组件传来的参数 sign 来表明是哪个区块的评论
getComments() {
// 获取评论
this.$http
/*带上自定义的标志作为id的属性名字*/
.get(`api/getcomments?${this.sign}=${this.id}&&pageindex=${this.pageIndex}`)
.then(result => {
if (result.body.status === 0) {
// this.comments = result.body.message;
// 每当获取新评论数据的时候,不要把老数据清空覆盖,而是应该以老数据,拼接上新数据
this.comments = this.comments.concat(result.body.result);
} else {
Toast("获取评论失败!");
}
});
},
```
### 添加评论
> 关于请求评论列表和添加评论需要添加的参数 区块标志 详情见
>
> 项目制作步骤 > 新闻版块 > 建立子组件 中查看this.sign值
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| --------------- | ---------------------------------- | ---- | ------------------------------------------------------------ | ------------------ |
| api/postcomment | status:0(正确)
status:1(错误) | POST | {"table": 区块标志
"com_id": 页面id, "add_time":评论时间 , "content": 评论内容} | result.body.result |
#### 列子
```javascript
// this.sign 是父组件传来的区块标志
this.$http
.post("api/postcomment",{
/*表名 带上自定义标志*/
table : this.sign,
com_id : this.$route.params.id,
add_time : this.CurentTime(),
content : this.msg.trim()
})
.then(function(result) {
if (result.body.status === 0) {
console.log(1);
// 1. 拼接出一个评论对象
var cmt = {
user_name: "匿名用户",
add_time: Date.now(),
content: this.msg.trim()
};
this.comments.unshift(cmt);
this.msg = "";
Toast({
message: '发表评论成功!!',
position: 'bottom',
duration: 1000
});
}
```
### 获取图片分类
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| ------------------- | ---------------------------------- | ---- | ---- | ------------------ |
| api/getPhotoCatList | status:0(正确)
status:1(错误) | GET | 无 | result.body.result |
#### 列子
```javascript
/*获取分类*/
getPrictureCatList() {
this.$http.get('api/getPhotoCatList').then(result =>{
if (result.body.status === 0 ) {
this.picturecat = result.body.result;
// 需要自己手动在前面添加一个“全部”的分类
this.picturecat.unshift({
'id':0,
'title':'全部'
})
} else {
Toast({
message: '分类数据加载失败',
position: 'bottom',
duration: 1500
});
}
});
},
```
### 获取图片列表
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| ---------------- | ---------------------------------- | ---- | --------------- | ------------------ |
| api/getPhotoList | status:0(正确)
status:1(错误) | GET | cat_id:分类的id | result.body.result |
#### 列子
```
/*获取图片列表*/
getPrictureList(cat_id) {
this.$http.get('api/getPhotoList?cat_id='+cat_id).then(result =>{
if (result.body.status === 0 ) {
this.picturelist = result.body.result;
} else {
Toast({
message: '图片列表数据加载失败',
position: 'bottom',
duration: 1500
});
}
});
}
```
### 获取图片详情
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| ------------------ | ---------------------------------- | ---- | --------------- | ------------------ |
| api/getPhotoObject | status:0(正确)
status:1(错误) | GET | id:图片文章的id | result.body.result |
#### 列子
```
// 获取图片文章详情页
getPhotoInfo() {
this.$http.get('api/getPhotoObject?id='+this.id).then(result =>{
if (result.body.status === 0 ) {
this.photoObject = result.body.result[0];
console.log(this.photoObject)
} else {
console.log(result.body)
Toast({
message: '图片详情数据加载失败',
position: 'bottom',
duration: 1500
});
}
})
}
```
### 获取图片文章的推按缩略图
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| ----------------- | ---------------------------------- | ---- | --------------- | ------------------ |
| api/getPhotoMater | status:0(正确)
status:1(错误) | GET | id:图片文章的id | result.body.result |
#### 列子
```
// 获取图片文章缩略图
getPhotoMater() {
this.$http.get('api/getPhotoMater?id='+this.id).then(result =>{
if (result.body.status === 0 ) {
result.body.result.forEach(item=>{
item.w = 820;
item.h = 512;
})
this.list = result.body.result;
console.log(this.list)
} else {
console.log(result.body)
Toast({
message: '图片缩略图数据加载失败',
position: 'bottom',
duration: 1500
});
}
})
}
```
### 获取商品列表的缩略图
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| ---------------- | ---------------------------------- | ---- | -------------- | ------------------ |
| api/getGoodsList | status:0(正确)
status:1(错误) | GET | pageIndex:页码 | result.body.result |
#### 列子
```
// 获取商品列表 需要传递页码
getGoodsList() {
this.$http.get(`api/getGoodsList?pageIndex=${this.page}`).then(result =>{
if (result.body.status === 0) {
this.goodslist = this.goodslist.concat(result.body.result)
} else {
Toast({
message: '商品数据加载失败',
position: 'bottom',
duration: 1500
});
}
})
}
```
### 获取商品详情
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| ----------------- | ---------------------------------- | ---- | ---------------- | ------------------ |
| api/getGoodObject | status:0(正确)
status:1(错误) | GET | goods_id:文章id | result.body.result |
#### 列子
```
// 获取商品列表 需要传递商品id
getGoodObject() {
this.$http.get(`api/getGoodObject?goods_id=${this.id}`).then(result =>{
if (result.body.status === 0 ) {
this.goodObject = result.body.result[0];
console.log(this.goodObject)
} else {
console.log(result.body)
Toast({
message: '商品详细数据加载失败',
position: 'bottom',
duration: 1500
});
}
})
}
```
### 获取商品详情中的轮播图图片
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| ------------------- | ---------------------------------- | ---- | ---------------- | ------------------ |
| api/getGoodsPicture | status:0(正确)
status:1(错误) | GET | goods_id:文章id | result.body.result |
#### 列子
```
// 获取商品列表 需要传递商品id
getGoodsPicture() {
this.$http.get(`api/getGoodsPicture?goods_id=${this.id}`).then(result =>{
if (result.body.status === 0 ) {
this.lunBoList = result.body.result;
console.log(this.lunBoList)
} else {
console.log(result.body)
Toast({
message: '商品轮播数据加载失败',
position: 'bottom',
duration: 1500
});
}
})
}
```
### 获取购物车中多个商品信息
#### 规则
| 地址 | 状态码 | 方式 | 参数 | 数据接受格式 |
| ---------------- | ---------------------------------- | ---- | --------------------------------- | ------------------ |
| api/getGoodsCart | status:0(正确)
status:1(错误) | GET | goods_ids:多个商品名,以逗号间隔 | result.body.result |
#### 列子
```
// 通过vuex从store中的car(购物车商品列表中获取多个商品id)拆分以逗号相隔
this.$store.state.car.forEach(item => {
this.idArray.push(item.goods_id);
})
this.$http.get(`api/getGoodsCart?goods_ids=${this.idArray.join(',')}`).then(result =>{
if (result.body.status === 0 ) {
this.goodsCarObject = result.body.result;
} else {
Toast({
message: '购物车商品数据加载失败',
position: 'bottom',
duration: 1500
});
}
})
}
```
## 项目制作步骤
### 首页根模板APP
#### 1.完成了Header 区域 ,使用的是Mint-UI的组件
```
//按需导入MintUi组件 顶部Header
import { Header } from 'mint-ui';
Vue.component(Header.name, Header);
//在app.vue中直接使用 放在
¥4999 ¥5999
热卖中 剩余60件
¥4999 ¥5999
热卖中 剩余60件
¥4999 ¥5999
热卖中 剩余60件