• 月木学途开发 6.网址模块


    概述

    效果图

     

    数据库设计

    网站类型表
    1. DROP TABLE IF EXISTS `website`;
    2. CREATE TABLE `website` (
    3.   `websiteId` int(11) NOT NULL AUTO_INCREMENT,
    4.   `websiteImg` longtext,
    5.   `websiteName` varchar(255) DEFAULT NULL,
    6.   `websiteUrl` longtext,
    7.   `websiteDesc` varchar(255) DEFAULT NULL,
    8.   `websiteTypeId` int(11) DEFAULT NULL,
    9.   PRIMARY KEY (`websiteId`)
    10. ) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4;

    网站表
    1. DROP TABLE IF EXISTS `website_type`;
    2. CREATE TABLE `website_type` (
    3.   `websiteTypeId` int(11) NOT NULL AUTO_INCREMENT,
    4.   `websiteTypeName` varchar(255) DEFAULT NULL,
    5.   PRIMARY KEY (`websiteTypeId`)
    6. ) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4;

    实体类设计

    WebsiteType
    1. package jkw.pojo;
    2. import com.baomidou.mybatisplus.annotation.TableField;
    3. import com.baomidou.mybatisplus.annotation.TableId;
    4. import lombok.Data;
    5. import java.io.Serializable;
    6. import java.util.List;
    7. /**
    8.  * 网站类型
    9.  */
    10. @Data
    11. public class WebsiteType implements Serializable {
    12.     @TableId
    13.     private Integer websiteTypeId;
    14.     private String websiteTypeName;//类型名
    15.     @TableField(exist = false)
    16.     private List websites;
    17. }

    Website
    1. package jkw.pojo;
    2. import com.baomidou.mybatisplus.annotation.TableId;
    3. import lombok.Data;
    4. import java.io.Serializable;
    5. /**
    6.  * 网站
    7.  */
    8. @Data
    9. public class Website implements Serializable {
    10.     @TableId
    11.     private Integer websiteId;
    12.     private String websiteImg;//图片
    13.     private String websiteName;//名称
    14.     private String websiteUrl;//url
    15.     private String websiteDesc;//描述
    16.     private Integer websiteTypeId;//类型
    17. }

    Mapper层开发

    WebsiteTypeMapper
    1. package jkw.mapper;
    2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
    3. import jkw.pojo.WebsiteType;
    4. public interface WebsiteTypeMapper extends BaseMapper<WebsiteType> {
    5. }

    WebsiteMapper
    1. package jkw.mapper;
    2. import com.baomidou.mybatisplus.core.mapper.BaseMapper;
    3. import jkw.pojo.Website;
    4. public interface WebsiteMapper extends BaseMapper<Website> {
    5. }

    Service层开发

    WebsiteTypeService
    1. package jkw.service;
    2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    3. import jkw.pojo.WebsiteType;
    4. import java.util.List;
    5. public interface WebsiteTypeService {
    6.     void add(WebsiteType WebsiteType);
    7.     void update(WebsiteType WebsiteType);
    8.     void delete(Integer id);
    9.     WebsiteType findById(Integer id);
    10.     List findAll();
    11.     Page search(String search, int page, int size);
    12. }

    WebsiteTypeServiceImpl
    1. package jkw.service.impl;
    2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    4. import jkw.mapper.WebsiteTypeMapper;
    5. import jkw.pojo.WebsiteType;
    6. import jkw.service.WebsiteTypeService;
    7. import org.springframework.beans.factory.annotation.Autowired;
    8. import org.springframework.stereotype.Service;
    9. import org.springframework.transaction.annotation.Transactional;
    10. import java.util.List;
    11. @Service
    12. @Transactional
    13. public class WebsiteTypeServiceImpl implements WebsiteTypeService {
    14.     @Autowired
    15.     private WebsiteTypeMapper WebsiteTypeMapper;
    16.     @Override
    17.     public void add(WebsiteType WebsiteType) {
    18.         WebsiteTypeMapper.insert(WebsiteType);
    19.     }
    20.     @Override
    21.     public void update(WebsiteType WebsiteType) {
    22.         WebsiteTypeMapper.updateById(WebsiteType);
    23.     }
    24.     @Override
    25.     public void delete(Integer id) {
    26.         WebsiteTypeMapper.deleteById(id);
    27.     }
    28.     @Override
    29.     public WebsiteType findById(Integer id) {
    30.         return WebsiteTypeMapper.selectById(id);
    31.     }
    32.     @Override
    33.     public List<WebsiteType> findAll() {
    34.         return WebsiteTypeMapper.selectList(null);
    35.     }
    36.     @Override
    37.     public Page<WebsiteType> search(String search, int page, int size) {
    38.         QueryWrapper queryWrapper = new QueryWrapper();
    39.         if (search != null) {
    40.         }
    41.         return WebsiteTypeMapper.selectPage(new Page<>(page, size), queryWrapper);
    42.     }
    43. }

    WebsiteService
    1. package jkw.service;
    2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    3. import jkw.pojo.Website;
    4. import java.util.List;
    5. public interface WebsiteService {
    6.     void add(Website Website);
    7.     void update(Website Website);
    8.     void delete(Integer id);
    9.     Website findById(Integer id);
    10.     List findAll();
    11.     Page search(String search, int page, int size);
    12.     //根据typeId查询
    13.     List findAllByWebsiteTypeId(Integer id);
    14. }

    WebsiteServiceImpl
    1. package jkw.service.impl;
    2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
    3. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    4. import jkw.pojo.Website;
    5. import jkw.service.WebsiteService;
    6. import org.springframework.beans.factory.annotation.Autowired;
    7. import org.springframework.stereotype.Service;
    8. import org.springframework.transaction.annotation.Transactional;
    9. import java.util.List;
    10. @Service
    11. @Transactional
    12. public class WebsiteServiceImpl implements WebsiteService {
    13.     @Autowired
    14.     private jkw.mapper.WebsiteMapper WebsiteMapper;
    15.     @Override
    16.     public void add(Website Website) {
    17.         WebsiteMapper.insert(Website);
    18.     }
    19.     @Override
    20.     public void update(Website Website) {
    21.         WebsiteMapper.updateById(Website);
    22.     }
    23.     @Override
    24.     public void delete(Integer id) {
    25.         WebsiteMapper.deleteById(id);
    26.     }
    27.     @Override
    28.     public Website findById(Integer id) {
    29.         return WebsiteMapper.selectById(id);
    30.     }
    31.     @Override
    32.     public List<Website> findAll() {
    33.         return WebsiteMapper.selectList(null);
    34.     }
    35.     @Override
    36.     public Page<Website> search(String search, int page, int size) {
    37.         QueryWrapper queryWrapper = new QueryWrapper();
    38.         if (search != null) {
    39.         }
    40.         return WebsiteMapper.selectPage(new Page<>(page, size), queryWrapper);
    41.     }
    42.     @Override
    43.     public List<Website> findAllByWebsiteTypeId(Integer id) {
    44.         QueryWrapper<Website> queryWrapper = new QueryWrapper<>();
    45.         queryWrapper.eq("websiteTypeId", id);
    46.         return WebsiteMapper.selectList(queryWrapper);
    47.     }
    48. }

    控制层开发

    WebsiteTypeCon
    1. package jkw.controller.back;
    2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    3. import jkw.pojo.WebsiteType;
    4. import jkw.service.WebsiteTypeService;
    5. import jkw.vo.BaseResult;
    6. import org.springframework.beans.factory.annotation.Autowired;
    7. import org.springframework.security.access.prepost.PreAuthorize;
    8. import org.springframework.web.bind.annotation.*;
    9. import java.util.List;
    10. @RequestMapping("/back/websiteType")
    11. @RestController
    12. @CrossOrigin
    13. public class WebsiteTypeCon {
    14.     @Autowired
    15.     private WebsiteTypeService WebsiteTypeService;
    16.     /**
    17.      * 新增
    18.      *
    19.      * @param WebsiteType
    20.      * @return
    21.      */
    22.     @PostMapping("/add")
    23.     @PreAuthorize("hasAnyAuthority('/website/website')")
    24.     public BaseResult add(WebsiteType WebsiteType) {
    25.         WebsiteTypeService.add(WebsiteType);
    26.         return BaseResult.ok();
    27.     }
    28.     /**
    29.      * 修改
    30.      *
    31.      * @param WebsiteType
    32.      * @return
    33.      */
    34.     @PostMapping("/update")
    35.     @PreAuthorize("hasAnyAuthority('/website/website')")
    36.     public BaseResult update(WebsiteType WebsiteType) {
    37.         WebsiteTypeService.update(WebsiteType);
    38.         return BaseResult.ok();
    39.     }
    40.     /**
    41.      * 删除
    42.      *
    43.      * @param websiteTypeId
    44.      * @return
    45.      */
    46.     @DeleteMapping("/delete")
    47.     @PreAuthorize("hasAnyAuthority('/website/website')")
    48.     public BaseResult delete(Integer websiteTypeId) {
    49.         WebsiteTypeService.delete(websiteTypeId);
    50.         return BaseResult.ok();
    51.     }
    52.     /**
    53.      * 根据id查询
    54.      *
    55.      * @param websiteTypeId
    56.      * @return
    57.      */
    58.     @GetMapping("/findById")
    59.     @PreAuthorize("hasAnyAuthority('/website/website')")
    60.     public BaseResult findById(Integer websiteTypeId) {
    61.         WebsiteType WebsiteType = WebsiteTypeService.findById(websiteTypeId);
    62.         return BaseResult.ok(WebsiteType);
    63.     }
    64.     /**
    65.      * 查询所有
    66.      *
    67.      * @return
    68.      */
    69.     @GetMapping("/findAll")
    70.     @PreAuthorize("hasAnyAuthority('/website/website')")
    71.     public BaseResult findAll() {
    72.         List<WebsiteType> all = WebsiteTypeService.findAll();
    73.         return BaseResult.ok(all);
    74.     }
    75.     /**
    76.      * 分页查询
    77.      *
    78.      * @param page
    79.      * @param size
    80.      * @return
    81.      */
    82.     @GetMapping("/search")
    83.     @PreAuthorize("hasAnyAuthority('/website/website')")
    84.     public BaseResult search(String search, int page, int size) {
    85.         Page<WebsiteType> brandPage = WebsiteTypeService.search(search, page, size);
    86.         return BaseResult.ok(brandPage);
    87.     }
    88. }

    WebsiteCon
    1. package jkw.controller.back;
    2. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
    3. import jkw.pojo.Website;
    4. import jkw.vo.BaseResult;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.security.access.prepost.PreAuthorize;
    7. import org.springframework.web.bind.annotation.*;
    8. import java.util.List;
    9. @RestController
    10. @RequestMapping("/back/website")
    11. @CrossOrigin
    12. public class WebsiteCon {
    13.     @Autowired
    14.     private jkw.service.WebsiteService WebsiteService;
    15.     /**
    16.      * 新增
    17.      *
    18.      * @param Website
    19.      * @return
    20.      */
    21.     @PostMapping("/add")
    22.     @PreAuthorize("hasAnyAuthority('/website/website')")
    23.     public BaseResult add(Website Website) {
    24.         WebsiteService.add(Website);
    25.         return BaseResult.ok();
    26.     }
    27.     /**
    28.      * 修改
    29.      *
    30.      * @param Website
    31.      * @return
    32.      */
    33.     @PostMapping("/update")
    34.     @PreAuthorize("hasAnyAuthority('/website/website')")
    35.     public BaseResult update(Website Website) {
    36.         WebsiteService.update(Website);
    37.         return BaseResult.ok();
    38.     }
    39.     /**
    40.      * 删除
    41.      *
    42.      * @param websiteId
    43.      * @return
    44.      */
    45.     @DeleteMapping("/delete")
    46.     @PreAuthorize("hasAnyAuthority('/website/website')")
    47.     public BaseResult delete(Integer websiteId) {
    48.         WebsiteService.delete(websiteId);
    49.         return BaseResult.ok();
    50.     }
    51.     /**
    52.      * 根据id查询
    53.      *
    54.      * @param websiteId
    55.      * @return
    56.      */
    57.     @GetMapping("/findById")
    58.     @PreAuthorize("hasAnyAuthority('/website/website')")
    59.     public BaseResult findById(Integer websiteId) {
    60.         Website Website = WebsiteService.findById(websiteId);
    61.         return BaseResult.ok(Website);
    62.     }
    63.     /**
    64.      * 查询所有
    65.      *
    66.      * @return
    67.      */
    68.     @GetMapping("/findAll")
    69.     @PreAuthorize("hasAnyAuthority('/website/website')")
    70.     public BaseResult findAll() {
    71.         List<Website> all = WebsiteService.findAll();
    72.         return BaseResult.ok(all);
    73.     }
    74.     /**
    75.      * 分页查询
    76.      *
    77.      * @param page
    78.      * @param size
    79.      * @return
    80.      */
    81.     @GetMapping("/search")
    82.     @PreAuthorize("hasAnyAuthority('/website/website')")
    83.     public BaseResult search(String search, int page, int size) {
    84.         Page<Website> brandPage = WebsiteService.search(search, page, size);
    85.         return BaseResult.ok(brandPage);
    86.     }
    87. }

    FrontWebsiteCon
    1. package jkw.controller.front;
    2. import jkw.pojo.Website;
    3. import jkw.pojo.WebsiteType;
    4. import jkw.service.WebsiteService;
    5. import jkw.service.WebsiteTypeService;
    6. import jkw.vo.BaseResult;
    7. import org.springframework.beans.factory.annotation.Autowired;
    8. import org.springframework.web.bind.annotation.CrossOrigin;
    9. import org.springframework.web.bind.annotation.GetMapping;
    10. import org.springframework.web.bind.annotation.RequestMapping;
    11. import org.springframework.web.bind.annotation.RestController;
    12. import java.util.List;
    13. @RequestMapping("/front/website")
    14. @RestController
    15. @CrossOrigin
    16. public class FrontWebsiteCon {
    17.     @Autowired
    18.     private WebsiteService websiteService;
    19.     @Autowired
    20.     private WebsiteTypeService websiteTypeService;
    21.     /**
    22.      * 查询所有网站类型以及对应的网站
    23.      *
    24.      * @return
    25.      */
    26.     @GetMapping("/findAllTypes")
    27.     public BaseResult findAllTypeWithWebsite() {
    28.         List websiteTypeList = websiteTypeService.findAll();
    29.         for (WebsiteType websiteType : websiteTypeList) {
    30.             List websiteList = websiteService.findAllByWebsiteTypeId(websiteType.getWebsiteTypeId());
    31.             websiteType.setWebsites(websiteList);
    32.         }
    33.         return BaseResult.ok(websiteTypeList);
    34.     }
    35. }

    后台ui设计

    WebsiteType.vue
    1. <template>
    2.   <div class="data-container">
    3.     <!--添加 start-->
    4.     <div class="data-header">
    5.       <el-input class="input" @keyup.enter="searchHandle" v-model="searchInfo" size="large"
    6.                 placeholder="请输入关键字"></el-input>
    7.       <el-button @click="searchHandle" class="button" size="large" type="primary" plain>搜索</el-button>
    8.       <el-button round @click="addHander" size="large" type="primary">
    9.         <el-icon>
    10.           <DocumentAdd/>
    11.         </el-icon>
    12.         <span>新增</span>
    13.       </el-button>
    14.     </div>
    15.     <!--添加 end-->
    16.     <!--表格数据展示 start-->
    17.     <div class="data-table">
    18.       <el-table :data="dataList.list" style="width: 550px;">
    19.         <el-table-column show-overflow-tooltip label="类型名" prop="websiteTypeName" align="center" width="300"></el-table-column>
    20.         <el-table-column label="操作" align="center" width="220">
    21.           <template #default="scope">
    22.             <el-button size="small" type="primary" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
    23.             <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
    24.           </template>
    25.         </el-table-column>
    26.       </el-table>
    27.       <!--分页 start-->
    28.       <div class="page">
    29.         <el-pagination background
    30.                        layout="prev,pager,next,jumper"
    31.                        :default-page-size="defaultPageSize"
    32.                        :total="totalData"
    33.                        @current-change="currentChangeHaddler"></el-pagination>
    34.       </div>
    35.       <!--分页 end-->
    36.     </div>
    37.     <!--表格数据展示 end-->
    38.     <!--添加对话框 start-->
    39.     <el-dialog draggable destroy-on-close v-model="dialogAddVisible" title="添加" width="35%" center>
    40.       <el-form inline :model="addFormInfo" label-width="150px">
    41.         <el-form-item label="类型名">
    42.           <el-input v-model="addFormInfo.websiteTypeName"></el-input>
    43.         </el-form-item>
    44.       </el-form>
    45.       <template #footer>
    46.             <span class="dialog-footer">
    47.                 <el-button @click="dialogAddVisible = false">取消</el-button>
    48.                 <el-button type="primary" @click="sureHandler">确定</el-button>
    49.             </span>
    50.       </template>
    51.     </el-dialog>
    52.     <!--添加对话框 end-->
    53.     <!--编辑对话框 start-->
    54.     <!--destroy-on-close:每次关闭对话框时直接销毁对话框,没有缓存-->
    55.     <el-dialog
    56.         draggable
    57.         destroy-on-close
    58.         v-model="dialogEditorVisible"
    59.         title="编辑"
    60.         width="35%"
    61.         center>
    62.       <el-form inline :model="editorFormInfo" label-width="150px">
    63.         <el-form-item label="类型名">
    64.           <el-input v-model="editorFormInfo.websiteTypeName"></el-input>
    65.         </el-form-item>
    66.       </el-form>
    67.       <template #footer>
    68.             <span class="dialog-footer">
    69.                 <el-button @click="dialogEditorVisible = false">取消</el-button>
    70.                 <el-button type="primary" @click="sureEditorHandler">确定</el-button>
    71.             </span>
    72.       </template>
    73.     </el-dialog>
    74.     <!--编辑对话框 end-->
    75.   </div>
    76. </template>
    77. <script setup>
    78. import axios from "../../api/index.js"
    79. import {onMounted, reactive, ref} from "vue";
    80. import {ElMessage} from "element-plus";
    81. //初始化分页查询数据
    82. const dataList = reactive({
    83.   list: []
    84. })
    85. //初始化总条数
    86. const totalData = ref(0)
    87. //当前页
    88. const currentPage = ref(1)
    89. //初始化分页显示条数
    90. const defaultPageSize = ref(10)
    91. //搜索初始化状态
    92. const searchInfo = ref("")
    93. //添加添加对话框控制器
    94. const dialogAddVisible = ref(false)
    95. //初始化添加对话框状态
    96. const addFormInfo = reactive({
    97.   websiteTypeName: "",
    98. })
    99. //编辑对话框控制器
    100. const dialogEditorVisible = ref(false)
    101. //初始化编辑对话框状态
    102. const editorFormInfo = reactive({
    103.   websiteTypeId: '',
    104.   websiteTypeName: "",
    105. })
    106. /**
    107.  * 网路请求:分页查询
    108.  *  */
    109. const http = (search, page, size) => {
    110.   axios.website_type_search({
    111.     search: search,
    112.     page: page,
    113.     size: size
    114.   }).then(res => {
    115.     if (res.data.code == 200) {
    116.       dataList.list = res.data.data.records
    117.       totalData.value = res.data.data.total
    118.     } else {
    119.       ElMessage.error(res.data.message)
    120.     }
    121.   })
    122. }
    123. onMounted(() => {
    124.   http(searchInfo.value, currentPage.value, defaultPageSize.value)
    125. })
    126. /**
    127.  * 分页
    128.  */
    129. const currentChangeHaddler = (nowPage) => {
    130.   http(searchInfo.value, nowPage, defaultPageSize.value)
    131.   currentPage.value = nowPage
    132. }
    133. /**
    134.  * 搜索按钮
    135.  */
    136. const searchHandle = () => {
    137.   http(searchInfo.value, currentPage.value, defaultPageSize.value)
    138. }
    139. /**
    140.  * 添加对话框弹出事件
    141.  */
    142. const addHander = () => {
    143.   dialogAddVisible.value = true
    144. }
    145. /**
    146.  * 添加对话框 确定事件
    147.  */
    148. const sureHandler = () => {
    149.   axios.website_type_add({
    150.     websiteTypeName: addFormInfo.websiteTypeName,
    151.   }).then(res => {
    152.     if (res.data.code == 200) {
    153.       dialogAddVisible.value = false
    154.       http(searchInfo.value, currentPage.value, defaultPageSize.value)
    155.     } else {
    156.       ElMessage.error(res.data.message)
    157.     }
    158.   })
    159. }
    160. /**
    161.  * 编辑对话框 弹出事件
    162.  *  */
    163. const handleEdit = (index, row) => {
    164.   dialogEditorVisible.value = true
    165.   axios.website_type_findById({
    166.     websiteTypeId: row.websiteTypeId
    167.   }).then(res => {
    168.     if (res.data.code == 200) {
    169.       editorFormInfo.websiteTypeId = res.data.data.websiteTypeId;
    170.       editorFormInfo.websiteTypeName = res.data.data.websiteTypeName;
    171.     } else {
    172.       ElMessage.error(res.data.data.message)
    173.     }
    174.   })
    175. }
    176. /**
    177.  * 编辑对话框 确定事件
    178.  */
    179. const sureEditorHandler = () => {
    180.   axios.website_type_update({
    181.     websiteTypeId: editorFormInfo.websiteTypeId,
    182.     websiteTypeName: editorFormInfo.websiteTypeName,
    183.   }).then(res => {
    184.     if (res.data.code == 200) {
    185.       dialogEditorVisible.value = false
    186.       http(searchInfo.value, currentPage.value, defaultPageSize.value)
    187.     } else {
    188.       ElMessage.error(res.data.message)
    189.     }
    190.   })
    191. }
    192. /**删除 */
    193. const handleDelete = (index, row) => {
    194.   ElMessageBox.confirm(
    195.       '确定删除么',
    196.       '删除',
    197.       {
    198.         confirmButtonText: '确定',
    199.         cancelButtonText: '取消',
    200.         type: 'warning',
    201.       }
    202.   ).then(() => {
    203.     //确认删除
    204.     axios.website_type_delete({
    205.       websiteTypeId: row.websiteTypeId
    206.     }).then(res => {
    207.       if (res.data.code == 200) {
    208.         ElMessage({
    209.           type: 'success',
    210.           message: "删除成功!!!",
    211.         })
    212.         //刷新
    213.         http(searchInfo.value, currentPage.value, defaultPageSize.value)
    214.       } else {
    215.         ElMessage({
    216.           type: 'error',
    217.           message: res.data.message,
    218.         })
    219.       }
    220.     })
    221.   }).catch(error => {
    222.     ElMessage({
    223.       type: 'info',
    224.       message: "取消删除",
    225.     })
    226.   })
    227. }
    228. </script>
    229. <style scoped>
    230. .data-container {
    231.   background: linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
    232.   background: -o-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
    233.   background: -ms-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
    234.   background: -moz-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
    235.   background: -webkit-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
    236.   height: 800px;
    237. }
    238. .data-header {
    239.   padding: 20px;
    240. }
    241. .data-header .input {
    242.   width: 300px;
    243. }
    244. .data-table {
    245.   padding: 20px;
    246. }
    247. .page {
    248.   position: fixed;
    249.   right: 10px;
    250.   bottom: 10px;
    251. }
    252. </style>

    Website.vue
    1. <template>
    2.   <div class="data-container">
    3.     <!--添加 start-->
    4.     <div class="data-header">
    5.       <el-input class="input" @keyup.enter="searchHandle" v-model="searchInfo" size="large"
    6.                 placeholder="请输入关键字"></el-input>
    7.       <el-button @click="searchHandle" class="button" size="large" type="primary" plain>搜索</el-button>
    8.       <el-button round @click="addHander" size="large" type="primary">
    9.         <el-icon>
    10.           <DocumentAdd/>
    11.         </el-icon>
    12.         <span>新增</span>
    13.       </el-button>
    14.     </div>
    15.     <!--添加 end-->
    16.     <!--表格数据展示 start-->
    17.     <div class="data-table">
    18.       <el-table :data="dataList.list" style="width: 1100px;">
    19.         <el-table-column label="图片" prop="websiteImg" align="center">
    20.           <template #default="scope">
    21.             <img :src="scope.row.websiteImg" style="height:60px"/>
    22.           </template>
    23.         </el-table-column>
    24.         <el-table-column label="类型" prop="websiteTypeId" align="center">
    25.           <template #default="scope">
    26.                   <span v-for="item in typeList.list" :key="item.websiteTypeId">
    27.                       {{ scope.row.websiteTypeId == item.websiteTypeId ? item.websiteTypeName : '' }}
    28.                   </span>
    29.           </template>
    30.         </el-table-column>
    31.         <el-table-column show-overflow-tooltip label="名称" prop="websiteName" align="center"></el-table-column>
    32.         <el-table-column show-overflow-tooltip label="url" prop="websiteUrl" align="center"></el-table-column>
    33.         <el-table-column show-overflow-tooltip label="描述" prop="websiteDesc" align="center"></el-table-column>
    34.         <el-table-column label="操作" align="center" width="220">
    35.           <template #default="scope">
    36.             <el-button size="small" type="primary" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
    37.             <el-button size="small" type="danger" @click="handleDelete(scope.$index, scope.row)">删除</el-button>
    38.           </template>
    39.         </el-table-column>
    40.       </el-table>
    41.       <!--分页 start-->
    42.       <div class="page">
    43.         <el-pagination background
    44.                        layout="prev,pager,next,jumper"
    45.                        :default-page-size="defaultPageSize"
    46.                        :total="totalData"
    47.                        @current-change="currentChangeHaddler"></el-pagination>
    48.       </div>
    49.       <!--分页 end-->
    50.     </div>
    51.     <!--表格数据展示 end-->
    52.     <!--添加对话框 start-->
    53.     <el-dialog draggable destroy-on-close v-model="dialogAddVisible" title="添加" width="35%" center>
    54.       <el-form inline :model="addFormInfo" label-width="150px">
    55.         <el-form-item label="图片">
    56.           <el-upload list-type="picture-card"
    57.                      :action="uploadStore.fastdfsUploadUrl"
    58.                      :on-success="onHeadImageAddSuccess"
    59.                      :on-remove="onHeadImageAddRemove">
    60.             <el-icon>
    61.             </el-icon>
    62.           </el-upload>
    63.         </el-form-item>
    64.         <el-form-item label="类型">
    65.           <el-select v-model="addFormInfo.websiteTypeId" placeholder="请选择类型" size="large">
    66.             <el-option v-for="item in typeList.list" :key="item.websiteTypeId"
    67.                        :label="item.websiteTypeName"
    68.                        :value="item.websiteTypeId">
    69.             </el-option>
    70.           </el-select>
    71.         </el-form-item>
    72.         <el-form-item label="名称">
    73.           <el-input v-model="addFormInfo.websiteName"></el-input>
    74.         </el-form-item>
    75.         <el-form-item label="url">
    76.           <el-input v-model="addFormInfo.websiteUrl"></el-input>
    77.         </el-form-item>
    78.         <el-form-item label="描述">
    79.           <el-input type="textarea" rows="6" style="width: 200px" v-model="addFormInfo.websiteDesc"></el-input>
    80.         </el-form-item>
    81.       </el-form>
    82.       <template #footer>
    83.             <span class="dialog-footer">
    84.                 <el-button @click="dialogAddVisible = false">取消</el-button>
    85.                 <el-button type="primary" @click="sureHandler">确定</el-button>
    86.             </span>
    87.       </template>
    88.     </el-dialog>
    89.     <!--添加对话框 end-->
    90.     <!--编辑对话框 start-->
    91.     <!--destroy-on-close:每次关闭对话框时直接销毁对话框,没有缓存-->
    92.     <el-dialog
    93.         draggable
    94.         destroy-on-close
    95.         v-model="dialogEditorVisible"
    96.         title="编辑"
    97.         width="35%"
    98.         center>
    99.       <el-form inline :model="editorFormInfo" label-width="150px">
    100.         <el-form-item label="头图">
    101.           <el-upload list-type="picture-card"
    102.                      :action="uploadStore.fastdfsUploadUrl"
    103.                      :on-success="onHeadImageEditSuccess"
    104.           >
    105.             <el-image :src="editorFormInfo.websiteImg"/>
    106.           </el-upload>
    107.         </el-form-item>
    108.         <el-form-item label="类型">
    109.           <el-select v-model="editorFormInfo.websiteTypeId" placeholder="请选择类型" size="large">
    110.             <el-option v-for="item in typeList.list" :key="item.websiteTypeId"
    111.                        :label="item.websiteTypeName"
    112.                        :value="item.websiteTypeId">
    113.             </el-option>
    114.           </el-select>
    115.         </el-form-item>
    116.         <el-form-item label="名称">
    117.           <el-input v-model="editorFormInfo.websiteName"></el-input>
    118.         </el-form-item>
    119.         <el-form-item label="url">
    120.           <el-input v-model="editorFormInfo.websiteUrl"></el-input>
    121.         </el-form-item>
    122.         <el-form-item label="描述">
    123.           <el-input type="textarea" rows="6" style="width: 200px" v-model="editorFormInfo.websiteDesc"></el-input>
    124.         </el-form-item>
    125.       </el-form>
    126.       <template #footer>
    127.             <span class="dialog-footer">
    128.                 <el-button @click="dialogEditorVisible = false">取消</el-button>
    129.                 <el-button type="primary" @click="sureEditorHandler">确定</el-button>
    130.             </span>
    131.       </template>
    132.     </el-dialog>
    133.     <!--编辑对话框 end-->
    134.   </div>
    135. </template>
    136. <script setup>
    137. import axios from "../../api/index.js"
    138. import {onMounted, reactive, ref} from "vue";
    139. import {ElMessage} from "element-plus";
    140. import {useUploadStore} from "../../stores/uploadStore.js"
    141. const uploadStore = useUploadStore()
    142. //初始化分页查询数据
    143. const dataList = reactive({
    144.   list: []
    145. })
    146. //初始化类型列表
    147. const typeList = reactive({
    148.   list: []
    149. })
    150. //初始化总条数
    151. const totalData = ref(0)
    152. //当前页
    153. const currentPage = ref(1)
    154. //初始化分页显示条数
    155. const defaultPageSize = ref(5)
    156. //搜索初始化状态
    157. const searchInfo = ref("")
    158. //添加添加对话框控制器
    159. const dialogAddVisible = ref(false)
    160. //初始化添加对话框状态
    161. const addFormInfo = reactive({
    162.   websiteImg: "",
    163.   websiteName: "",
    164.   websiteUrl: "",
    165.   websiteDesc: "",
    166.   websiteTypeId: ''
    167. })
    168. //编辑对话框控制器
    169. const dialogEditorVisible = ref(false)
    170. //初始化编辑对话框状态
    171. const editorFormInfo = reactive({
    172.   websiteId: '',
    173.   websiteImg: "",
    174.   websiteName: "",
    175.   websiteUrl: "",
    176.   websiteDesc: "",
    177.   websiteTypeId: ''
    178. })
    179. /**
    180.  * 网路请求:分页查询
    181.  *  */
    182. const http = (search, page, size) => {
    183.   axios.website_search({
    184.     search: search,
    185.     page: page,
    186.     size: size
    187.   }).then(res => {
    188.     if (res.data.code == 200) {
    189.       dataList.list = res.data.data.records
    190.       totalData.value = res.data.data.total
    191.     } else {
    192.       ElMessage.error(res.data.message)
    193.     }
    194.   })
    195. }
    196. onMounted(() => {
    197.   http(searchInfo.value, currentPage.value, defaultPageSize.value)
    198.   axios.website_type_findAll().then(res => {
    199.     if (res.data.code == 200) {
    200.       typeList.list = res.data.data
    201.     }
    202.   })
    203. })
    204. /**
    205.  * 分页
    206.  */
    207. const currentChangeHaddler = (nowPage) => {
    208.   http(searchInfo.value, nowPage, defaultPageSize.value)
    209.   currentPage.value = nowPage
    210. }
    211. /**
    212.  * 搜索按钮
    213.  */
    214. const searchHandle = () => {
    215.   http(searchInfo.value, currentPage.value, defaultPageSize.value)
    216. }
    217. /**
    218.  * 添加对话框弹出事件
    219.  */
    220. const addHander = () => {
    221.   dialogAddVisible.value = true
    222. }
    223. //上传成功的钩子
    224. const onHeadImageAddSuccess = (response, uploadFile) => {
    225.   addFormInfo.websiteImg = response.data
    226.   ElMessage.success("上传成功")
    227. }
    228. //移除图片的钩子
    229. const onHeadImageAddRemove = (response, uploadFile) => {
    230.   axios.fastdfs_delete({
    231.     filePath: addFormInfo.websiteImg
    232.   }).then(res => {
    233.     if (res.data.code == 200) {
    234.       ElMessage.success("移除成功")
    235.     }
    236.   })
    237. }
    238. /**
    239.  * 添加对话框 确定事件
    240.  */
    241. const sureHandler = () => {
    242.   axios.website_add({
    243.     websiteImg: addFormInfo.websiteImg,
    244.     websiteName: addFormInfo.websiteName,
    245.     websiteUrl: addFormInfo.websiteUrl,
    246.     websiteDesc: addFormInfo.websiteDesc,
    247.     websiteTypeId: addFormInfo.websiteTypeId,
    248.   }).then(res => {
    249.     if (res.data.code == 200) {
    250.       dialogAddVisible.value = false
    251.       http(searchInfo.value, currentPage.value, defaultPageSize.value)
    252.     } else {
    253.       ElMessage.error(res.data.message)
    254.     }
    255.   })
    256. }
    257. /**
    258.  * 编辑对话框 弹出事件
    259.  *  */
    260. const handleEdit = (index, row) => {
    261.   dialogEditorVisible.value = true
    262.   axios.website_findById({
    263.     websiteId: row.websiteId
    264.   }).then(res => {
    265.     if (res.data.code == 200) {
    266.       editorFormInfo.websiteId = res.data.data.websiteId;
    267.       editorFormInfo.websiteImg = res.data.data.websiteImg;
    268.       editorFormInfo.websiteName = res.data.data.websiteName;
    269.       editorFormInfo.websiteUrl = res.data.data.websiteUrl;
    270.       editorFormInfo.websiteDesc = res.data.data.websiteDesc;
    271.       editorFormInfo.websiteTypeId = res.data.data.websiteTypeId;
    272.     } else {
    273.       ElMessage.error(res.data.data.message)
    274.     }
    275.   })
    276. }
    277. /**
    278.  * 编辑对话框 头图修改时图片上传成功事件
    279.  */
    280.     //上传成功的钩子
    281. const onHeadImageEditSuccess = (response, uploadFile) => {
    282.       //删除以前图片
    283.       axios.fastdfs_delete({
    284.         filePath: editorFormInfo.websiteImg
    285.       }).then(res => {
    286.         if (res.data.code == 200) {
    287.           ElMessage.success("fastdfs移除原图片成功")
    288.         }
    289.       })
    290.       //替换为现在的图片
    291.       editorFormInfo.websiteImg = response.data
    292.       ElMessage.success("上传成功")
    293.     }
    294. /**
    295.  * 编辑对话框 确定事件
    296.  */
    297. const sureEditorHandler = () => {
    298.   axios.website_update({
    299.     websiteId: editorFormInfo.websiteId,
    300.     websiteImg: editorFormInfo.websiteImg,
    301.     websiteName: editorFormInfo.websiteName,
    302.     websiteUrl: editorFormInfo.websiteUrl,
    303.     websiteDesc: editorFormInfo.websiteDesc,
    304.     websiteTypeId: editorFormInfo.websiteTypeId,
    305.   }).then(res => {
    306.     if (res.data.code == 200) {
    307.       dialogEditorVisible.value = false
    308.       http(searchInfo.value, currentPage.value, defaultPageSize.value)
    309.     } else {
    310.       ElMessage.error(res.data.message)
    311.     }
    312.   })
    313. }
    314. /**删除 */
    315. const handleDelete = (index, row) => {
    316.   ElMessageBox.confirm(
    317.       '确定删除么',
    318.       '删除',
    319.       {
    320.         confirmButtonText: '确定',
    321.         cancelButtonText: '取消',
    322.         type: 'warning',
    323.       }
    324.   ).then(() => {
    325.     //确认删除
    326.     axios.website_delete({
    327.       websiteId: row.websiteId
    328.     }).then(res => {
    329.       if (res.data.code == 200) {
    330.         ElMessage({
    331.           type: 'success',
    332.           message: "删除成功!!!",
    333.         })
    334.         //刷新
    335.         http(searchInfo.value, currentPage.value, defaultPageSize.value)
    336.       } else {
    337.         ElMessage({
    338.           type: 'error',
    339.           message: res.data.message,
    340.         })
    341.       }
    342.     })
    343.   }).catch(error => {
    344.     ElMessage({
    345.       type: 'info',
    346.       message: "取消删除",
    347.     })
    348.   })
    349. }
    350. </script>
    351. <style scoped>
    352. .data-container {
    353.   background: linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
    354.   background: -o-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
    355.   background: -ms-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
    356.   background: -moz-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
    357.   background: -webkit-linear-gradient(left, rgb(89, 234, 233) 27%, rgb(131, 231, 218) 44%, rgb(69, 150, 216) 88%);
    358.   height: 800px;
    359. }
    360. .data-header {
    361.   padding: 20px;
    362. }
    363. .data-header .input {
    364.   width: 300px;
    365. }
    366. .data-table {
    367.   padding: 20px;
    368. }
    369. .page {
    370.   position: fixed;
    371.   right: 10px;
    372.   bottom: 10px;
    373. }
    374. </style>

  • 相关阅读:
    无涯教程-JavaScript - LOG函数
    嵌入式中C++ 编程习惯与编程要点分析
    Qt编写跨平台RTSP/RTMP/HTTP视频流播放器
    高可用技术
    SDL2 简单介绍以及Windows开发环境搭建
    【图像处理】关于颜色的万花筒(RGB--HSV)
    内网横向移动——SNMP获取信息
    python项目实战——银行取款机系统(八)
    智能化嵌入式设备设计:人工智能与物联网的融合创新
    从0到1手把手教你ASP.NET Core Web API项目配置接口文档Swagger(一)
  • 原文地址:https://blog.csdn.net/m0_63040701/article/details/133134323