生成侧边栏导航菜单

image.png

使用人人开源逆向生成的前端代码作为页面组件

将逆向工程product得到的resources\src\views\modules\product文件拷贝到gulimall/renren-fast-vue/src/views/modules/product目录下,也就是下面的两个文件

brand.vue ——品牌列表
brand-add-or-update.vue —— 品牌增加修改

权限认证关闭

image.png

优化逆向生成代码

brand.vue

  1. <template>
  2. <div class="mod-config">
  3. <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
  4. <el-form-item>
  5. <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>
  6. </el-form-item>
  7. <el-form-item>
  8. <el-button @click="getDataList()">查询</el-button>
  9. <el-button
  10. v-if="isAuth('product:brand:save')"
  11. type="primary"
  12. @click="addOrUpdateHandle()"
  13. >新增
  14. </el-button>
  15. <el-button
  16. v-if="isAuth('product:brand:delete')"
  17. type="danger"
  18. @click="deleteHandle()"
  19. :disabled="dataListSelections.length <= 0"
  20. >批量删除
  21. </el-button>
  22. </el-form-item>
  23. </el-form>
  24. <el-table
  25. :data="dataList"
  26. border
  27. v-loading="dataListLoading"
  28. @selection-change="selectionChangeHandle"
  29. style="width: 100%;"
  30. >
  31. <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
  32. <el-table-column prop="brandId" header-align="center" align="center" label="品牌id"></el-table-column>
  33. <el-table-column prop="name" header-align="center" align="center" label="品牌名"></el-table-column>
  34. <el-table-column prop="logo" header-align="center" align="center" label="品牌logo地址">
  35. <template slot-scope="scope">
  36. <!-- <el-image
  37. style="width: 100px; height: 80px"
  38. :src="scope.row.logo"
  39. fit="fill"></el-image>-->
  40. <img :src="scope.row.logo" style="width: 100px; height: 80px"/>
  41. </template>
  42. </el-table-column>
  43. <el-table-column prop="descript" header-align="center" align="center" label="介绍"></el-table-column>
  44. <el-table-column prop="showStatus" header-align="center" align="center" label="显示状态">
  45. <template slot-scope="scope">
  46. <el-switch
  47. v-model="scope.row.showStatus"
  48. active-color="#13ce66"
  49. inactive-color="#ff4949"
  50. :active-value="1"
  51. :inactive-value="0"
  52. @change="updateBrandStatus(scope.row)"
  53. ></el-switch>
  54. </template>
  55. </el-table-column>
  56. <el-table-column prop="firstLetter" header-align="center" align="center" label="检索首字母"></el-table-column>
  57. <el-table-column prop="sort" header-align="center" align="center" label="排序"></el-table-column>
  58. <el-table-column fixed="right" header-align="center" align="center" width="250" label="操作">
  59. <template slot-scope="scope">
  60. <el-button type="text" size="small" @click="updateCatelogHandle(scope.row.brandId)">关联分类</el-button>
  61. <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.brandId)">修改</el-button>
  62. <el-button type="text" size="small" @click="deleteHandle(scope.row.brandId)">删除</el-button>
  63. </template>
  64. </el-table-column>
  65. </el-table>
  66. <el-pagination
  67. @size-change="sizeChangeHandle"
  68. @current-change="currentChangeHandle"
  69. :current-page="pageIndex"
  70. :page-sizes="[10, 20, 50, 100]"
  71. :page-size="pageSize"
  72. :total="totalPage"
  73. layout="total, sizes, prev, pager, next, jumper"
  74. ></el-pagination>
  75. <!-- 弹窗, 新增 / 修改 -->
  76. <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  77. <el-dialog title="关联分类" :visible.sync="cateRelationDialogVisible" width="30%">
  78. <el-popover placement="right-end" v-model="popCatelogSelectVisible">
  79. <category-cascader :catelogPath.sync="catelogPath"></category-cascader>
  80. <div style="text-align: right; margin: 0">
  81. <el-button size="mini" type="text" @click="popCatelogSelectVisible = false">取消</el-button>
  82. <el-button type="primary" size="mini" @click="addCatelogSelect">确定</el-button>
  83. </div>
  84. <el-button slot="reference">新增关联</el-button>
  85. </el-popover>
  86. <el-table :data="cateRelationTableData" style="width: 100%">
  87. <el-table-column prop="id" label="#"></el-table-column>
  88. <el-table-column prop="brandName" label="品牌名"></el-table-column>
  89. <el-table-column prop="catelogName" label="分类名"></el-table-column>
  90. <el-table-column fixed="right" header-align="center" align="center" label="操作">
  91. <template slot-scope="scope">
  92. <el-button
  93. type="text"
  94. size="small"
  95. @click="deleteCateRelationHandle(scope.row.id,scope.row.brandId)"
  96. >移除
  97. </el-button>
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. <span slot="footer" class="dialog-footer">
  102. <el-button @click="cateRelationDialogVisible = false">取 消</el-button>
  103. <el-button type="primary" @click="cateRelationDialogVisible = false">确 定</el-button>
  104. </span>
  105. </el-dialog>
  106. </div>
  107. </template>
  108. <script>
  109. import AddOrUpdate from "./brand-add-or-update";
  110. // import CategoryCascader from "../common/category-cascader";
  111. export default {
  112. data() {
  113. return {
  114. dataForm: {
  115. key: ""
  116. },
  117. brandId: 0,
  118. catelogPath: [],
  119. dataList: [],
  120. cateRelationTableData: [],
  121. pageIndex: 1,
  122. pageSize: 10,
  123. totalPage: 0,
  124. dataListLoading: false,
  125. dataListSelections: [],
  126. addOrUpdateVisible: false,
  127. cateRelationDialogVisible: false,
  128. popCatelogSelectVisible: false
  129. };
  130. },
  131. components: {
  132. AddOrUpdate,
  133. // CategoryCascader
  134. },
  135. activated() {
  136. this.getDataList();
  137. },
  138. methods: {
  139. addCatelogSelect() {
  140. //{"brandId":1,"catelogId":2}
  141. this.popCatelogSelectVisible = false;
  142. this.$http({
  143. url: this.$http.adornUrl("/product/categorybrandrelation/save"),
  144. method: "post",
  145. data: this.$http.adornData({
  146. brandId: this.brandId,
  147. catelogId: this.catelogPath[this.catelogPath.length - 1]
  148. }, false)
  149. }).then(({data}) => {
  150. this.getCateRelation();
  151. });
  152. },
  153. deleteCateRelationHandle(id, brandId) {
  154. this.$http({
  155. url: this.$http.adornUrl("/product/categorybrandrelation/delete"),
  156. method: "post",
  157. data: this.$http.adornData([id], false)
  158. }).then(({data}) => {
  159. this.getCateRelation();
  160. });
  161. },
  162. updateCatelogHandle(brandId) {
  163. this.cateRelationDialogVisible = true;
  164. this.brandId = brandId;
  165. this.getCateRelation();
  166. },
  167. getCateRelation() {
  168. this.$http({
  169. url: this.$http.adornUrl("/product/categorybrandrelation/catelog/list"),
  170. method: "get",
  171. params: this.$http.adornParams({
  172. brandId: this.brandId
  173. })
  174. }).then(({data}) => {
  175. this.cateRelationTableData = data.data;
  176. });
  177. },
  178. // 获取数据列表
  179. getDataList() {
  180. this.dataListLoading = true;
  181. this.$http({
  182. url: this.$http.adornUrl("/product/brand/list"),
  183. method: "get",
  184. params: this.$http.adornParams({
  185. page: this.pageIndex,
  186. limit: this.pageSize,
  187. key: this.dataForm.key
  188. })
  189. }).then(({data}) => {
  190. if (data && data.code === 0) {
  191. this.dataList = data.page.list;
  192. this.totalPage = data.page.totalCount;
  193. } else {
  194. this.dataList = [];
  195. this.totalPage = 0;
  196. }
  197. this.dataListLoading = false;
  198. });
  199. },
  200. updateBrandStatus(data) {
  201. console.log("最新信息", data);
  202. let {brandId, showStatus} = data;
  203. //发送请求修改状态
  204. this.$http({
  205. url: this.$http.adornUrl("/product/brand/update/status"),
  206. method: "post",
  207. data: this.$http.adornData({brandId, showStatus}, false)
  208. }).then(({data}) => {
  209. this.$message({
  210. type: "success",
  211. message: "状态更新成功"
  212. });
  213. });
  214. },
  215. // 每页数
  216. sizeChangeHandle(val) {
  217. this.pageSize = val;
  218. this.pageIndex = 1;
  219. this.getDataList();
  220. },
  221. // 当前页
  222. currentChangeHandle(val) {
  223. this.pageIndex = val;
  224. this.getDataList();
  225. },
  226. // 多选
  227. selectionChangeHandle(val) {
  228. this.dataListSelections = val;
  229. },
  230. // 新增 / 修改
  231. addOrUpdateHandle(id) {
  232. this.addOrUpdateVisible = true;
  233. this.$nextTick(() => {
  234. this.$refs.addOrUpdate.init(id);
  235. });
  236. },
  237. // 删除
  238. deleteHandle(id) {
  239. var ids = id
  240. ? [id]
  241. : this.dataListSelections.map(item => {
  242. return item.brandId;
  243. });
  244. this.$confirm(
  245. `确定对[id=${ids.join(",")}]进行[${id ? "删除" : "批量删除"}]操作?`,
  246. "提示",
  247. {
  248. confirmButtonText: "确定",
  249. cancelButtonText: "取消",
  250. type: "warning"
  251. }
  252. ).then(() => {
  253. this.$http({
  254. url: this.$http.adornUrl("/product/brand/delete"),
  255. method: "post",
  256. data: this.$http.adornData(ids, false)
  257. }).then(({data}) => {
  258. if (data && data.code === 0) {
  259. this.$message({
  260. message: "操作成功",
  261. type: "success",
  262. duration: 1500,
  263. onClose: () => {
  264. this.getDataList();
  265. }
  266. });
  267. } else {
  268. this.$message.error(data.msg);
  269. }
  270. });
  271. });
  272. }
  273. }
  274. };
  275. </script>
  276. <style scoped>
  277. </style>

brand-add-or-update.vue

  1. <template>
  2. <el-dialog
  3. :title="!dataForm.id ? '新增' : '修改'"
  4. :close-on-click-modal="false"
  5. :visible.sync="visible"
  6. >
  7. <el-form
  8. :model="dataForm"
  9. :rules="dataRule"
  10. ref="dataForm"
  11. @keyup.enter.native="dataFormSubmit()"
  12. label-width="140px"
  13. >
  14. <el-form-item label="品牌名" prop="name">
  15. <el-input v-model="dataForm.name" placeholder="品牌名"></el-input>
  16. </el-form-item>
  17. <el-form-item label="品牌logo地址" prop="logo">
  18. <!-- <el-input v-model="dataForm.logo" placeholder="品牌logo地址"></el-input> -->
  19. <single-upload v-model="dataForm.logo"></single-upload>
  20. </el-form-item>
  21. <el-form-item label="介绍" prop="descript">
  22. <el-input v-model="dataForm.descript" placeholder="介绍"></el-input>
  23. </el-form-item>
  24. <el-form-item label="显示状态" prop="showStatus">
  25. <el-switch
  26. v-model="dataForm.showStatus"
  27. active-color="#13ce66"
  28. inactive-color="#ff4949"
  29. :active-value="1"
  30. :inactive-value="0"
  31. ></el-switch>
  32. </el-form-item>
  33. <el-form-item label="检索首字母" prop="firstLetter">
  34. <el-input v-model="dataForm.firstLetter" placeholder="检索首字母"></el-input>
  35. </el-form-item>
  36. <el-form-item label="排序" prop="sort">
  37. <el-input v-model.number="dataForm.sort" placeholder="排序"></el-input>
  38. </el-form-item>
  39. </el-form>
  40. <span slot="footer" class="dialog-footer">
  41. <el-button @click="visible = false">取消</el-button>
  42. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  43. </span>
  44. </el-dialog>
  45. </template>
  46. <script>
  47. import SingleUpload from '@/components/upload/singleUpload';
  48. export default {
  49. components: {SingleUpload},
  50. data() {
  51. return {
  52. visible: false,
  53. dataForm: {
  54. brandId: 0,
  55. name: "",
  56. logo: "",
  57. descript: "",
  58. showStatus: 1,
  59. firstLetter: "",
  60. sort: 0
  61. },
  62. dataRule: {
  63. name: [{required: true, message: "品牌名不能为空", trigger: "blur"}],
  64. logo: [
  65. {required: true, message: "品牌logo地址不能为空", trigger: "blur"}
  66. ],
  67. descript: [
  68. {required: true, message: "介绍不能为空", trigger: "blur"}
  69. ],
  70. showStatus: [
  71. {
  72. required: true,
  73. message: "显示状态[0-不显示;1-显示]不能为空",
  74. trigger: "blur"
  75. }
  76. ],
  77. firstLetter: [
  78. {
  79. validator: (rule, value, callback) => {
  80. if (value == "") {
  81. callback(new Error("首字母必须填写"));
  82. } else if (!/^[a-zA-Z]$/.test(value)) {
  83. callback(new Error("首字母必须a-z或者A-Z之间"));
  84. } else {
  85. callback();
  86. }
  87. },
  88. trigger: "blur"
  89. }
  90. ],
  91. sort: [
  92. {
  93. validator: (rule, value, callback) => {
  94. if (value == "") {
  95. callback(new Error("排序字段必须填写"));
  96. } else if (!Number.isInteger(value) || value < 0) {
  97. callback(new Error("排序必须是一个大于等于0的整数"));
  98. } else {
  99. callback();
  100. }
  101. },
  102. trigger: "blur"
  103. }
  104. ]
  105. }
  106. };
  107. },
  108. methods: {
  109. init(id) {
  110. this.dataForm.brandId = id || 0;
  111. this.visible = true;
  112. this.$nextTick(() => {
  113. this.$refs["dataForm"].resetFields();
  114. if (this.dataForm.brandId) {
  115. this.$http({
  116. url: this.$http.adornUrl(
  117. `/product/brand/info/${this.dataForm.brandId}`
  118. ),
  119. method: "get",
  120. params: this.$http.adornParams()
  121. }).then(({data}) => {
  122. if (data && data.code === 0) {
  123. this.dataForm.name = data.brand.name;
  124. this.dataForm.logo = data.brand.logo;
  125. this.dataForm.descript = data.brand.descript;
  126. this.dataForm.showStatus = data.brand.showStatus;
  127. this.dataForm.firstLetter = data.brand.firstLetter;
  128. this.dataForm.sort = data.brand.sort;
  129. }
  130. });
  131. }
  132. });
  133. },
  134. // 表单提交
  135. dataFormSubmit() {
  136. this.$refs["dataForm"].validate(valid => {
  137. if (valid) {
  138. this.$http({
  139. url: this.$http.adornUrl(
  140. `/product/brand/${!this.dataForm.brandId ? "save" : "update"}`
  141. ),
  142. method: "post",
  143. data: this.$http.adornData({
  144. brandId: this.dataForm.brandId || undefined,
  145. name: this.dataForm.name,
  146. logo: this.dataForm.logo,
  147. descript: this.dataForm.descript,
  148. showStatus: this.dataForm.showStatus,
  149. firstLetter: this.dataForm.firstLetter,
  150. sort: this.dataForm.sort
  151. })
  152. }).then(({data}) => {
  153. if (data && data.code === 0) {
  154. this.$message({
  155. message: "操作成功",
  156. type: "success",
  157. duration: 1500,
  158. onClose: () => {
  159. this.visible = false;
  160. this.$emit("refreshDataList");
  161. }
  162. });
  163. } else {
  164. this.$message.error(data.msg);
  165. }
  166. });
  167. }
  168. });
  169. }
  170. }
  171. };
  172. </script>