• 电商后台管理系统(基于SSM + Vue + Restful + jquery + axios)


    1.项目架构

    2.config配置

    JdbcConfig

    1. public class JdbcConfig {
    2. @Value("${jdbc.driver}")
    3. private String driver;
    4. @Value("${jdbc.url}")
    5. private String url;
    6. @Value("${jdbc.username}")
    7. private String username;
    8. @Value("${jdbc.password}")
    9. private String password;
    10. @Bean
    11. public DataSource dataSource(){
    12. DruidDataSource dataSource = new DruidDataSource();
    13. dataSource.setDriverClassName(driver);
    14. dataSource.setUrl(url);
    15. dataSource.setUsername(username);
    16. dataSource.setPassword(password);
    17. return dataSource;
    18. }
    19. @Bean
    20. public PlatformTransactionManager transactionManager(DataSource dataSource){
    21. DataSourceTransactionManager ds = new DataSourceTransactionManager(dataSource);
    22. return ds;
    23. }
    24. }

     MyBatisConfig

    1. public class MyBatisConfig {
    2. @Bean
    3. public SqlSessionFactoryBean sqlSessionFactory(DataSource dataSource){
    4. SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
    5. factoryBean.setTypeAliasesPackage("cn.itaxu.domain");
    6. factoryBean.setDataSource(dataSource);
    7. return factoryBean;
    8. }
    9. @Bean
    10. public MapperScannerConfigurer mapperScannerConfigurer(){
    11. MapperScannerConfigurer msc = new MapperScannerConfigurer();
    12. msc.setBasePackage("cn.itaxu.dao");
    13. return msc;
    14. }
    15. }

    ServletConfig

    1. public class ServletConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    2. // 加载spring配置
    3. @Override
    4. protected Class[] getRootConfigClasses() {
    5. return new Class[]{SpringConfig.class};
    6. }
    7. // 加载springMVC配置
    8. @Override
    9. protected Class[] getServletConfigClasses() {
    10. return new Class[]{SpringMvcConfig.class};
    11. }
    12. // 设置哪些方法归属springMVC处理
    13. @Override
    14. protected String[] getServletMappings() {
    15. return new String[]{"/"};
    16. }
    17. // 处理POST请求中文乱码问题
    18. @Override
    19. protected Filter[] getServletFilters() {
    20. CharacterEncodingFilter filter = new CharacterEncodingFilter("UTF-8");
    21. return new Filter[]{filter};
    22. }
    23. }

    SpringConfig

    1. @Configuration
    2. @ComponentScan("cn.itaxu.service")
    3. @PropertySource("classpath:jdbc.properties")
    4. @Import({JdbcConfig.class,MyBatisConfig.class})
    5. @EnableTransactionManagement
    6. public class SpringConfig {
    7. }

    SpringMvcConfig

    1. @Configuration
    2. @ComponentScan({"cn.itaxu.controller","cn.itaxu.config"})
    3. @EnableWebMvc
    4. public class SpringMvcConfig {
    5. }

    SpringMvcSupport

    1. @Configuration
    2. public class SpringMvcSupport extends WebMvcConfigurationSupport {
    3. @Override
    4. protected void addResourceHandlers(ResourceHandlerRegistry registry) {
    5. registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");
    6. registry.addResourceHandler("/img/**").addResourceLocations("/img/");
    7. }
    8. }

    3.controller控制

    BrandController

    1. @RestController
    2. @RequestMapping("/brands")
    3. public class BrandController {
    4. @Autowired
    5. private BrandService brandService;
    6. @PostMapping
    7. public Result save(@RequestBody Brand brand){
    8. boolean flag = brandService.save(brand);
    9. return new Result(flag ? Code.SAVE_OK:Code.SAVE_ERR,flag);
    10. }
    11. @DeleteMapping("/{id}")
    12. public Result deleteById(@PathVariable Integer id){
    13. boolean flag = brandService.deleteById(id);
    14. return new Result(flag ? Code.DELETE_OK:Code.DELETE_ERR,flag);
    15. }
    16. @DeleteMapping
    17. public Result deleteMultiply(@RequestBody int[] ids){
    18. boolean flag = brandService.deleteMultiply(ids);
    19. return new Result(flag ? Code.DELETE_OK:Code.DELETE_ERR,flag);
    20. }
    21. @PutMapping
    22. public Result update(@RequestBody Brand brand){
    23. System.out.println(brand);
    24. boolean flag = brandService.update(brand);
    25. return new Result(flag ? Code.UPDATE_OK:Code.UPDATE_ERR,flag);
    26. }
    27. @GetMapping("/{id}")
    28. public Result getById(@PathVariable Integer id){
    29. Brand brand = brandService.getById(id);
    30. Integer code =brand != null ? Code.GET_OK:Code.GET_ERR;
    31. String msg = brand != null ? "success":"fail";
    32. return new Result(code,brand,msg);
    33. }
    34. @GetMapping
    35. public Result getAll(){
    36. List brandList = brandService.getAll();
    37. Integer code = brandList != null ? Code.GET_OK:Code.GET_ERR;
    38. String msg = brandList != null ? "success":"fail";
    39. return new Result(code,brandList,msg);
    40. }
    41. @PostMapping("/{currentPage}/{pageSize}")
    42. public Result selectByPageAndCondition(@PathVariable int currentPage,@PathVariable int pageSize,
    43. @RequestBody Brand brand) {
    44. PageBean pageBean = brandService.selectByPageAndCondition(currentPage, pageSize, brand);
    45. Integer code = pageBean != null ? Code.GET_OK:Code.GET_ERR;
    46. String msg = pageBean != null ? "success":"fail";
    47. return new Result(code,pageBean,msg);
    48. }
    49. }

    Code 响应状态码

    1. public class Code {
    2. public static final Integer SAVE_OK = 20011;
    3. public static final Integer DELETE_OK = 20021;
    4. public static final Integer UPDATE_OK = 20031;
    5. public static final Integer GET_OK = 20041;
    6. public static final Integer SAVE_ERR = 20010;
    7. public static final Integer DELETE_ERR = 20020;
    8. public static final Integer UPDATE_ERR = 20030;
    9. public static final Integer GET_ERR = 20040;
    10. public static final Integer SYSTEM_ERR = 50001;
    11. public static final Integer SYSTEM_TIMEOUT_ERR = 50002;
    12. public static final Integer SYSTEM_UNKNOW_ERR = 59999;
    13. public static final Integer BUSINESS_ERR = 60002;
    14. }
    ProjectExceptionAdvice 项目异常通知
    1. @RestControllerAdvice
    2. public class ProjectExceptionAdvice {
    3. @ExceptionHandler(SystemException.class)
    4. public Result doSystemException(SystemException ex){
    5. // 记录日志
    6. // 发送消息给运维
    7. // 发送消息给开发人员,ex对象发送给开发人员
    8. return new Result(ex.getCode(),"null","系统异常");
    9. }
    10. @ExceptionHandler(BusinessException.class)
    11. public Result doBusinessException(BusinessException ex){
    12. return new Result(ex.getCode(),"null","业务异常");
    13. }
    14. @ExceptionHandler(Exception.class)
    15. public Result doException(Exception ex){
    16. // 记录日志
    17. // 发送消息给运维
    18. // 发送消息给开发人员,ex对象发送给开发人员
    19. return new Result(Code.SYSTEM_UNKNOW_ERR,"null","系统繁忙,请稍后再试!");
    20. }
    21. }

    Result 统一格式数据

    1. public class Result {
    2. private Object data;
    3. private Integer code;
    4. private String msg;
    5. public Result() {
    6. }
    7. public Result(Integer code,Object data) {
    8. this.data = data;
    9. this.code = code;
    10. }
    11. public Result(Integer code, Object data, String msg) {
    12. this.data = data;
    13. this.code = code;
    14. this.msg = msg;
    15. }
    16. public Object getData() {
    17. return data;
    18. }
    19. public void setData(Object data) {
    20. this.data = data;
    21. }
    22. public Integer getCode() {
    23. return code;
    24. }
    25. public void setCode(Integer code) {
    26. this.code = code;
    27. }
    28. public String getMsg() {
    29. return msg;
    30. }
    31. public void setMsg(String msg) {
    32. this.msg = msg;
    33. }
    34. }

    4.exception 细化异常

    BusinessException 业务异常

    1. public class BusinessException extends RuntimeException{
    2. private Integer code;
    3. public Integer getCode() {
    4. return code;
    5. }
    6. public void setCode(Integer code) {
    7. this.code = code;
    8. }
    9. public BusinessException(Integer code, String message) {
    10. super(message);
    11. this.code = code;
    12. }
    13. public BusinessException(Integer code, String message, Throwable cause) {
    14. super(message, cause);
    15. this.code = code;
    16. }
    17. }
    SystemException 系统异常
    1. public class SystemException extends RuntimeException{
    2. private Integer code;
    3. public Integer getCode() {
    4. return code;
    5. }
    6. public void setCode(Integer code) {
    7. this.code = code;
    8. }
    9. public SystemException(Integer code, String message) {
    10. super(message);
    11. this.code = code;
    12. }
    13. public SystemException(Integer code, String message, Throwable cause) {
    14. super(message, cause);
    15. this.code = code;
    16. }
    17. }

    5.service

    BrandService接口

    1. @Transactional
    2. public interface BrandService {
    3. /**
    4. * 添加数据
    5. * @param brand
    6. * @return
    7. */
    8. public boolean save(Brand brand);
    9. /**
    10. * 根据id删除
    11. * @param id
    12. * @return
    13. */
    14. public boolean deleteById(Integer id);
    15. /**
    16. * 根据ids批量删除
    17. * @param ids
    18. * @return
    19. */
    20. public boolean deleteMultiply(@Param("ids") int[] ids);
    21. /**
    22. * 修改数据
    23. * @param brand
    24. * @return
    25. */
    26. public boolean update(Brand brand);
    27. /**
    28. * 查询单条
    29. * @param id
    30. * @return
    31. */
    32. public Brand getById(Integer id);
    33. /**
    34. * 查询所有
    35. * @return
    36. */
    37. public List getAll();
    38. /**
    39. * 分页查询
    40. * @param currentPage
    41. * @param pageSize
    42. * @return
    43. */
    44. PageBean selectByPage(int currentPage, int pageSize);
    45. /**
    46. * 分页条件查询
    47. * @param currentPage
    48. * @param pageSize
    49. * @param brand
    50. * @return
    51. */
    52. PageBean selectByPageAndCondition(int currentPage, int pageSize, Brand brand);
    53. }

    BrandServiceImpl

    1. @Service
    2. public class BrandServiceImpl implements BrandService {
    3. @Autowired
    4. private BrandDao brandDao;
    5. @Override
    6. public boolean save(Brand brand) {
    7. return brandDao.save(brand) > 0;
    8. }
    9. @Override
    10. public boolean deleteById(Integer id) {
    11. return brandDao.deleteById(id) > 0;
    12. }
    13. @Override
    14. public boolean deleteMultiply(int[] ids) {
    15. return brandDao.deleteMultiply(ids) > 0;
    16. }
    17. @Override
    18. public boolean update(Brand brand) {
    19. return brandDao.update(brand) > 0;
    20. }
    21. @Override
    22. public Brand getById(Integer id) {
    23. return brandDao.getById(id);
    24. }
    25. @Override
    26. public List getAll() {
    27. return brandDao.getAll();
    28. }
    29. @Override
    30. public PageBean selectByPage(int currentPage, int pageSize) {
    31. int begin = (currentPage-1) * pageSize;
    32. int size = pageSize;
    33. List rows = brandDao.selectByPage(begin, size);
    34. int totalCount = brandDao.selectTotalCount();
    35. PageBean pageBean = new PageBean();
    36. pageBean.setRows(rows);
    37. pageBean.setTotalCount(totalCount);
    38. return pageBean;
    39. }
    40. @Override
    41. public PageBean selectByPageAndCondition(int currentPage, int pageSize, Brand brand) {
    42. int begin = (currentPage-1) * pageSize;
    43. int size = pageSize;
    44. // 处理模糊查询
    45. String brandName = brand.getBrandName();
    46. if (brandName!=null&&brandName.length()>0){
    47. brand.setBrandName("%"+brandName+"%");
    48. }
    49. String companyName = brand.getCompanyName();
    50. if (companyName!=null&&companyName.length()>0){
    51. brand.setCompanyName("%"+companyName+"%");
    52. }
    53. // 查询当前页数据
    54. List brandList = brandDao.selectByPageAndCondition(begin, size, brand);
    55. // 查询当前页总记录条数
    56. int totalCount = brandDao.selectTotalCountByCondition(brand);
    57. // 封装PageBean
    58. PageBean pageBean = new PageBean<>(brandList,totalCount);
    59. return pageBean;
    60. }
    61. }

    6.前端代码

    1. <div id="app">
    2. <el-menu
    3. :default-active="activeIndex2"
    4. class="el-menu-demo"
    5. mode="horizontal"
    6. @select="handleSelect"
    7. background-color="#545c64"
    8. text-color="#fff"
    9. active-text-color="#ffd04b">
    10. <template>
    11. <h3 align="center"><img src="../img/E-commerce.png" width="50" height="50" align="center">
    12. 电商后台数据模型
    13. h3>
    14. template>
    15. <el-menu-item index="1">处理中心el-menu-item>
    16. <el-submenu index="2">
    17. <template slot="title">我的工作台template>
    18. <el-menu-item index="2-1">后台品牌模型el-menu-item>
    19. el-submenu>
    20. <el-menu-item index="3" disabled>消息中心el-menu-item>
    21. <el-menu-item index="4"><a href="https://www.ele.me" target="_blank">订单管理a>el-menu-item>
    22. el-menu>
    23. <el-form :inline="true" :model="brand" class="demo-form-inline">
    24. <el-form-item label="当前状态">
    25. <el-select v-model="brand.status" placeholder="当前状态">
    26. <el-option label="启用" value="1">el-option>
    27. <el-option label="禁用" value="0">el-option>
    28. el-select>
    29. el-form-item>
    30. <el-form-item label="企业名称">
    31. <el-input v-model="brand.companyName" placeholder="企业名称">el-input>
    32. el-form-item>
    33. <el-form-item label="品牌名称">
    34. <el-input v-model="brand.brandName" placeholder="品牌名称">el-input>
    35. el-form-item>
    36. <el-form-item>
    37. <el-button type="primary" @click="onSubmit">查询el-button>
    38. el-form-item>
    39. el-form>
    40. <el-row style="margin-left: 20%">
    41. <el-button type="danger" plain @click="deleteBrandByIds">批量删除el-button>
    42. <el-button type="primary" plain @click="dialogVisible = true">新增el-button>
    43. el-row>
    44. <el-dialog
    45. title="编辑品牌"
    46. :visible.sync="dialogVisible"
    47. width="30%"
    48. >
    49. <el-form ref="form" :model="brand_add" label-width="80px">
    50. <el-form-item label="品牌名称">
    51. <el-input v-model="brand_add.brandName">el-input>
    52. el-form-item>
    53. <el-form-item label="企业名称">
    54. <el-input v-model="brand_add.companyName">el-input>
    55. el-form-item>
    56. <el-form-item label="排序">
    57. <el-input v-model="brand_add.ordered">el-input>
    58. el-form-item>
    59. <el-form-item label="备注">
    60. <el-input type="textarea" v-model="brand_add.description">el-input>
    61. el-form-item>
    62. <el-form-item label="状态">
    63. <el-switch
    64. v-model="brand_add.status"
    65. active-value="1"
    66. inactive-value="0"
    67. >
    68. el-switch>
    69. el-form-item>
    70. <el-form-item>
    71. <el-button type="primary" @click="addBrand">提交el-button>
    72. <el-button @click="cancelAdd">取消el-button>
    73. el-form-item>
    74. el-form>
    75. el-dialog>
    76. <el-dialog
    77. title="修改数据"
    78. :visible.sync="updateDialogVisible"
    79. width="30%">
    80. <el-form ref="form" :model="update" label-width="80px">
    81. <el-form-item label="品牌名称">
    82. <el-input v-model="update.brandName">el-input>
    83. el-form-item>
    84. <el-form-item label="企业名称">
    85. <el-input v-model="update.companyName">el-input>
    86. el-form-item>
    87. <el-form-item label="排序">
    88. <el-input v-model="update.ordered">el-input>
    89. el-form-item>
    90. <el-form-item label="备注">
    91. <el-input type="textarea" v-model="update.description">el-input>
    92. el-form-item>
    93. <el-form-item label="状态">
    94. <el-switch
    95. v-model="update.status"
    96. active-value="1"
    97. inactive-value="0">
    98. el-switch>
    99. el-form-item>
    100. <el-form-item>
    101. <el-button type="primary" @click="updateBrand">提交el-button>
    102. <el-button @click="cancel">取消el-button>
    103. el-form-item>
    104. el-form>
    105. el-dialog>
    106. <h4 align="center"><img src="../img/product.png" width="50" height="50" align="center"><font color="gray">产品列表
    107. font>h4>
    108. <template>
    109. <el-table
    110. :data="tableData"
    111. style="width: 100%"
    112. :row-class-name="tableRowClassName"
    113. @selection-change="handleSelectionChange"
    114. >
    115. <el-table-column
    116. type="selection"
    117. width="55"
    118. >
    119. el-table-column>
    120. <el-table-column
    121. type="index"
    122. width="50">
    123. el-table-column>
    124. <el-table-column
    125. prop="brandName"
    126. label="品牌名称"
    127. align="center"
    128. >
    129. el-table-column>
    130. <el-table-column
    131. prop="companyName"
    132. label="企业名称"
    133. align="center"
    134. >
    135. el-table-column>
    136. <el-table-column
    137. prop="ordered"
    138. label="排序"
    139. align="center"
    140. >
    141. el-table-column>
    142. <el-table-column
    143. prop="description"
    144. label="备注"
    145. align="center"
    146. >
    147. el-table-column>
    148. <el-table-column
    149. prop="statusStr"
    150. label="当前状态"
    151. align="center"
    152. >
    153. el-table-column>
    154. <el-table-column
    155. prop="address"
    156. label="操作"
    157. align="center"
    158. >
    159. <el-row>
    160. <el-button type="primary" @click="modify">修改el-button>
    161. <el-button type="danger" @click="deleteById">删除el-button>
    162. el-row>
    163. el-table-column>
    164. el-table>
    165. template>
    166. <div class="block">
    167. <el-pagination
    168. @size-change="handleSizeChange"
    169. @current-change="handleCurrentChange"
    170. :current-page="currentPage"
    171. :page-sizes="[5, 10, 15, 20]"
    172. :page-size="pageSize"
    173. layout="total, sizes, prev, pager, next, jumper"
    174. :total="totalCount">
    175. el-pagination>
    176. div>
    177. div>

    js

    1. <script src="https://cdn.staticfile.org/axios/1.1.3/axios.js">script>
    2. <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.10/theme-chalk/index.css">
    3. <script src="https://cdn.staticfile.org/element-ui/2.15.10/index.js">script>
    4. <script>
    5. new Vue({
    6. el:"#app",
    7. mounted(){
    8. //当页面加载完毕后,发送异步请求
    9. this.selectAll();
    10. },
    11. methods: {
    12. // 查询所有品牌数据
    13. selectAll(){
    14. axios({
    15. method:"post",
    16. url:`/brands/${this.currentPage}/${this.pageSize}`,
    17. data:this.brand,
    18. headers: {
    19. 'Content-Type': 'application/json;charset=UTF-8'
    20. }
    21. }).then((resp)=>{
    22. if (resp.data.code == 20041) {
    23. this.tableData = resp.data.data.rows;
    24. this.totalCount = resp.data.data.totalCount
    25. }else if (resp.data.code == 20040){
    26. this.$message.error('获取数据失败!').center = true;
    27. }else {
    28. this.$message.error(resp.data.msg).center = true;
    29. }
    30. })
    31. },
    32. resetForm(formName) {
    33. this.$refs[formName].resetFields();
    34. },
    35. cancelAdd(){
    36. this.dialogVisible = false;
    37. // 用户点击了取消按钮
    38. this.$message({
    39. showClose: true,
    40. message: '您取消了添加数据!',
    41. center:true
    42. });
    43. },
    44. modify(){
    45. for (let i = 0; i < this.multipleSelection.length; i++) {
    46. var selectionElement = this.multipleSelection[i];
    47. this.update.id = selectionElement.id;
    48. }
    49. if (this.update.id == '' || this.update.id == null){
    50. this.$message({
    51. showClose: true,
    52. message: '请选中您要修改的数据!',
    53. type: 'error',
    54. center:true,
    55. });
    56. return;
    57. }
    58. axios.get(`/brands/${this.update.id}`).then((resp)=>{
    59. if (resp.data.code==20041){
    60. this.update = resp.data.data;
    61. this.updateDialogVisible = true;
    62. }
    63. });
    64. },
    65. cancel(){
    66. this.updateDialogVisible = false;
    67. this.$message({
    68. showClose: true,
    69. message: '您已取消修改',
    70. center:true
    71. });
    72. },
    73. tableRowClassName({row, rowIndex}) {
    74. if (rowIndex === 1) {
    75. return 'warning-row';
    76. } else if (rowIndex === 3) {
    77. return 'success-row';
    78. }
    79. return '';
    80. },
    81. // 复选框选中后执行的方法
    82. handleSelectionChange(val) {
    83. this.multipleSelection = val;
    84. },
    85. // 查询的方法
    86. onSubmit() {
    87. this.selectAll();
    88. },
    89. // 添加数据
    90. addBrand(){
    91. axios({
    92. method:'post',
    93. url:'/brands',
    94. data:this.brand_add,
    95. headers:{
    96. 'Content-Type':'application/json;charset=UTF-8'
    97. }
    98. }).then( (resp) => {
    99. if (resp.data.code==20011){
    100. // 关闭添加数据对话框表单
    101. this.dialogVisible = false;
    102. // 弹出提示信息
    103. this.$message({
    104. message: '添加数据成功!',
    105. type: 'success',
    106. center: true
    107. });
    108. }else if (resp.data.code==20010){
    109. this.$message.error("添加数据失败!").center = true;
    110. }else {
    111. this.$message.error(resp.data.msg).center = true;
    112. }
    113. }).finally(()=>{
    114. // 重新查询数据
    115. this.selectAll();
    116. this.resetForm(this.brand_add)
    117. })
    118. },
    119. // 更新数据
    120. updateBrand(){
    121. axios.put("/brands",this.update).then(resp=>{
    122. if (resp.data.code == 20031) {
    123. this.updateDialogVisible = false;
    124. this.$message({
    125. showClose: true,
    126. message: '更新数据成功!',
    127. type: 'success',
    128. center: true
    129. });
    130. }else if (resp.data.code == 20030){
    131. this.$message.error("更新数据失败!").center = true
    132. }else {
    133. this.$message.error(resp.data.msg).center = true
    134. }
    135. }).finally(()=>{
    136. this.selectAll();
    137. });
    138. this.update.id = '';
    139. },
    140. // 批量删除
    141. deleteBrandByIds(){
    142. // 弹出确认提示框
    143. this.$confirm('此操作将永久删除数据, 是否继续?', '提示', {
    144. confirmButtonText: '确定',
    145. cancelButtonText: '取消',
    146. type: 'warning'
    147. }).then(() => {
    148. // 1.创建id数组,从this.multipleSelection中获取
    149. for (let i = 0; i < this.multipleSelection.length; i++) {
    150. let selectionElement = this.multipleSelection[i];
    151. this.selectedIds[i] = selectionElement.id
    152. }
    153. if (this.selectedIds.length < 1){
    154. this.$message({
    155. showClose: true,
    156. message: '请选中您要删除的数据!',
    157. type: 'error',
    158. center:true,
    159. });
    160. return;
    161. }
    162. // 2.发送ajax请求
    163. axios({
    164. method: 'delete',
    165. url: '/brands',
    166. data:this.selectedIds,
    167. headers:{
    168. 'Content-Type':'application/json;charset=utf-8'
    169. }
    170. }).then( (resp) => {
    171. if (resp.data.code == 20021) {
    172. // 重新查询数据
    173. this.selectAll();
    174. this.$message({
    175. type: 'success',
    176. message: '删除成功!',
    177. center: true
    178. });
    179. }else if (resp.data.code == 20020){
    180. this.$message.error("删除失败!").center = true
    181. }else {
    182. this.$message.error(resp.data.msg).center = true
    183. }
    184. });
    185. }).catch(() => {
    186. // 用户点击取消按钮
    187. this.$message({
    188. type: 'info',
    189. message: '您已取消删除',
    190. center:true
    191. });
    192. });
    193. // 清除数组
    194. this.selectedIds = [];
    195. },
    196. // 删除单条数据
    197. deleteById(){
    198. for (let i = 0; i < this.multipleSelection.length; i++) {
    199. var selectionElement = this.multipleSelection[i];
    200. this.selectedId = selectionElement.id;
    201. }
    202. if (this.selectedId == '' || this.selectedId == null){
    203. this.$message({
    204. showClose: true,
    205. message: '请选中您要删除的数据!',
    206. type: 'error',
    207. center:true,
    208. });
    209. return;
    210. }
    211. axios.delete(`/brands/${this.selectedId}`)
    212. .then(resp=>{
    213. this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
    214. confirmButtonText: '确定',
    215. cancelButtonText: '取消',
    216. type: 'warning'
    217. }).then(() => {
    218. if (resp.data.code == 20021) {
    219. this.$message({
    220. type: 'success',
    221. message: '删除成功!',
    222. center: true
    223. });
    224. }else if (resp.data.code == 20020){
    225. this.$message.error("删除失败!").center = true
    226. }else {
    227. this.$message.error(resp.data.msg).center = true
    228. }
    229. }).catch(() => {
    230. this.$message({
    231. type: 'info',
    232. message: '您已取消删除',
    233. center:true,
    234. });
    235. });
    236. }).finally(()=>{
    237. // 重新查询数据
    238. this.selectAll();
    239. });
    240. // 清空selectedId
    241. this.selectedId = ''
    242. },
    243. // 分页
    244. handleSizeChange(val) {
    245. // 重新设置每页显示条数
    246. this.pageSize = val;
    247. this.selectAll();
    248. },
    249. handleCurrentChange(val) {
    250. // 重新设置当前页码
    251. this.currentPage = val;
    252. this.selectAll();
    253. }
    254. },
    255. data() {
    256. return {
    257. // 被选中的单个id
    258. selectedId:'',
    259. // 总记录条数
    260. totalCount:'',
    261. // 每页显示条数
    262. pageSize:10,
    263. // 修改数据表单显示状态
    264. updateDialogVisible:false,
    265. // 当前页码
    266. currentPage:1,
    267. // 控制添加数据对话框表单是否显示
    268. dialogVisible: false,
    269. // 品牌模型数据
    270. brand: {
    271. companyName: '',
    272. status: '',
    273. brandName:'',
    274. id:'',
    275. ordered:'',
    276. description:'',
    277. },
    278. // 更新模型数据
    279. update: {
    280. companyName: '',
    281. status: '',
    282. brandName:'',
    283. id:'',
    284. ordered:'',
    285. description:'',
    286. },
    287. // 添加模型数据
    288. brand_add: {
    289. companyName: '',
    290. status: '',
    291. brandName:'',
    292. id:'',
    293. ordered:'',
    294. description:'',
    295. },
    296. // 复选框选中数据集合
    297. multipleSelection:[],
    298. // 被选中的id数组
    299. selectedIds:[],
    300. // 表格数据
    301. tableData: []
    302. }
    303. },
    304. })
    305. script>

    7.页面展示

     

     

     

    结语:

    希望这些能够帮助到你的学习!!! 如果有需要源码的私信我

  • 相关阅读:
    【色彩管理】ICC曲线制作教程
    工业设计里的四个细节你知道吗?
    MySQL数据库进阶操作(超详细大总结)
    获取一段程序运行的时间
    Spring 6【数据绑定之类型转换(Type Conversion)】(十一)-全面详解(学习总结---从入门到深化)
    【机器学习】课程设计布置:某闯关类手游用户流失预测
    ES 知识
    隔离上网,安全上网
    大语言模型(LLM)综述(四):如何适应预训练后的大语言模型
    危化企业双重预防机制数字化建设进入全面实施阶段
  • 原文地址:https://blog.csdn.net/weixin_64144937/article/details/127910971