生成侧边栏导航菜单

image.png

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

image.png
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

<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible"
  >
    <el-form
      :model="dataForm"
      :rules="dataRule"
      ref="dataForm"
      @keyup.enter.native="dataFormSubmit()"
      label-width="140px"
    >
      <el-form-item label="品牌名" prop="name">
        <el-input v-model="dataForm.name" placeholder="品牌名"></el-input>
      </el-form-item>
      <el-form-item label="品牌logo地址" prop="logo">
        <!-- <el-input v-model="dataForm.logo" placeholder="品牌logo地址"></el-input> -->
        <single-upload v-model="dataForm.logo"></single-upload>
      </el-form-item>
      <el-form-item label="介绍" prop="descript">
        <el-input v-model="dataForm.descript" placeholder="介绍"></el-input>
      </el-form-item>
      <el-form-item label="显示状态" prop="showStatus">
        <el-switch
          v-model="dataForm.showStatus"
          active-color="#13ce66"
          inactive-color="#ff4949"
          :active-value="1"
          :inactive-value="0"
        ></el-switch>
      </el-form-item>
      <el-form-item label="检索首字母" prop="firstLetter">
        <el-input v-model="dataForm.firstLetter" placeholder="检索首字母"></el-input>
      </el-form-item>
      <el-form-item label="排序" prop="sort">
        <el-input v-model.number="dataForm.sort" placeholder="排序"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import SingleUpload from '@/components/upload/singleUpload';

export default {
  components: {SingleUpload},
  data() {
    return {
      visible: false,
      dataForm: {
        brandId: 0,
        name: "",
        logo: "",
        descript: "",
        showStatus: 1,
        firstLetter: "",
        sort: 0
      },
      dataRule: {
        name: [{required: true, message: "品牌名不能为空", trigger: "blur"}],
        logo: [
          {required: true, message: "品牌logo地址不能为空", trigger: "blur"}
        ],
        descript: [
          {required: true, message: "介绍不能为空", trigger: "blur"}
        ],
        showStatus: [
          {
            required: true,
            message: "显示状态[0-不显示;1-显示]不能为空",
            trigger: "blur"
          }
        ],
        firstLetter: [
          {
            validator: (rule, value, callback) => {
              if (value == "") {
                callback(new Error("首字母必须填写"));
              } else if (!/^[a-zA-Z]$/.test(value)) {
                callback(new Error("首字母必须a-z或者A-Z之间"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ],
        sort: [
          {
            validator: (rule, value, callback) => {
              if (value == "") {
                callback(new Error("排序字段必须填写"));
              } else if (!Number.isInteger(value) || value < 0) {
                callback(new Error("排序必须是一个大于等于0的整数"));
              } else {
                callback();
              }
            },
            trigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    init(id) {
      this.dataForm.brandId = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs["dataForm"].resetFields();
        if (this.dataForm.brandId) {
          this.$http({
            url: this.$http.adornUrl(
              `/product/brand/info/${this.dataForm.brandId}`
            ),
            method: "get",
            params: this.$http.adornParams()
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.dataForm.name = data.brand.name;
              this.dataForm.logo = data.brand.logo;
              this.dataForm.descript = data.brand.descript;
              this.dataForm.showStatus = data.brand.showStatus;
              this.dataForm.firstLetter = data.brand.firstLetter;
              this.dataForm.sort = data.brand.sort;
            }
          });
        }
      });
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs["dataForm"].validate(valid => {
        if (valid) {
          this.$http({
            url: this.$http.adornUrl(
              `/product/brand/${!this.dataForm.brandId ? "save" : "update"}`
            ),
            method: "post",
            data: this.$http.adornData({
              brandId: this.dataForm.brandId || undefined,
              name: this.dataForm.name,
              logo: this.dataForm.logo,
              descript: this.dataForm.descript,
              showStatus: this.dataForm.showStatus,
              firstLetter: this.dataForm.firstLetter,
              sort: this.dataForm.sort
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: "操作成功",
                type: "success",
                duration: 1500,
                onClose: () => {
                  this.visible = false;
                  this.$emit("refreshDataList");
                }
              });
            } else {
              this.$message.error(data.msg);
            }
          });
        }
      });
    }
  }
};
</script>