当前位置:   article > 正文

vue表单筛选_vue 表格条件筛选

vue 表格条件筛选

目录

筛选

HTML

scss*

filterComp

排序

表格

自定义数据样式

inner-table

分页

删除

default-modal

自定义元素的插槽-占位符


  1. .search-wrap {
  2. height: 60px;
  3. display: flex;
  4. align-items: center;
  5. overflow: hidden;
  6. padding: 0 20px;
  7. .selected-options-wrap {
  8. flex: 1;
  9. .clear-btn {
  10. display: inline-block;
  11. text-align: center;
  12. color: #dd2100;
  13. margin-left: 12px;
  14. padding: 0 6px;
  15. border-radius: 4px;
  16. background-color: rgba(221, 33, 0, .1);
  17. cursor: pointer;
  18. }
  19. }
  20. .mds-tag {
  21. padding-right: 0;
  22. margin-left: 8px;
  23. border-radius: 4px;
  24. border: 1px solid #d9ecff;
  25. cursor:default;
  26. .mds-btn {
  27. height: auto;
  28. }
  29. }
  30. .mds-input-search {
  31. width: 240px;
  32. ::v-deep .mds-input {
  33. border-radius: 4px;
  34. }
  35. }
  36. .filter-btn {
  37. margin-left: 12px;
  38. position: relative;
  39. .mds-btn {
  40. padding: 0;
  41. width: 32px;
  42. height: 32px;
  43. }
  44. .filter-count {
  45. width: 18px;
  46. height: 18px;
  47. line-height: 18px;
  48. text-align: center;
  49. position: absolute;
  50. top: -9px;
  51. right: -9px;
  52. color: #fff;
  53. background-color: #0364ff;
  54. border-radius: 50%;
  55. }
  56. .filter-icon {
  57. width: 28px;
  58. height: 28px;
  59. object-fit: cover;
  60. position: relative;
  61. top: 1px;
  62. }
  63. .filter-num {
  64. position: absolute;
  65. top: -10px;
  66. right: -2px;
  67. width: 16px;
  68. height: 16px;
  69. border-radius: 50%;
  70. background-color: #1564ff;
  71. color: #fff;
  72. font-size: 12px;
  73. line-height: 16px;
  74. }
  75. }
  76. }

filterComp

  1. <template>
  2. <mds-drawer
  3. title="条件筛选"
  4. :visibility="visibility"
  5. size="720px"
  6. @close="cancelFilterDrawer"
  7. >
  8. <mds-form label-width="100px" :model="filterList" label-position="right">
  9. <mds-form-item label="发布状态">
  10. <mds-select placeholder="发布状态" style="width: 100%" clearable v-model="filterList.releStat">
  11. <mds-option label="未发布" value="0" />
  12. <mds-option label="已发布" value="1" />
  13. </mds-select>
  14. </mds-form-item>
  15. ...
  16. <mds-form-item label="更新时间">
  17. <mds-date-picker
  18. v-model="timeArr"
  19. type="daterange"
  20. range-separator="至"
  21. start-placeholder="开始日期"
  22. end-placeholder="结束日期"
  23. format="yyyy-MM-dd"
  24. value-format="yyyy-MM-dd"
  25. @change="changeTime"
  26. ></mds-date-picker>
  27. </mds-form-item>
  28. </mds-form>
  29. <template slot="footer">
  30. <mds-button @click="cancelFilterDrawer">取消</mds-button>
  31. <mds-button type="primary" @click="saveFilter">确认</mds-button>
  32. </template>
  33. </mds-drawer>
  34. </template>
  35. <script lang="ts">
  36. import { Component, Vue, Prop } from 'vue-property-decorator'
  37. @Component({
  38. components: {}
  39. })
  40. export default class FilterComp extends Vue {
  41. @Prop({ required: true }) private visibility!: boolean
  42. timeArr = []
  43. filterList: any = {
  44. moduTyp: '', // 模块
  45. releStat: "", //发布状态
  46. updateStartDate: '',
  47. updateEndDate: ''
  48. }
  49. // 修改时间
  50. changeTime(val: any) {
  51. this.filterList.updateStartDate = val ? val[0] : ''
  52. this.filterList.updateEndDate = val ? val[1] : ''
  53. }
  54. // 清除选项
  55. clearOptions(option: string) {
  56. if (option === 'all') {
  57. this.filterList = {}
  58. this.timeArr = []
  59. } else if (option === 'time') {
  60. this.filterList.updateStartDate = ''
  61. this.filterList.updateEndDate = ''
  62. this.timeArr = []
  63. } else {
  64. this.filterList[option] = ''
  65. }
  66. this.saveFilter()
  67. }
  68. // 取消筛选
  69. cancelFilterDrawer() {
  70. this.$emit('update:visibility', false)
  71. }
  72. // 保存筛选
  73. saveFilter() {
  74. const data = {
  75. ...this.filterList
  76. }
  77. this.$emit('changeFilter', data)
  78. this.cancelFilterDrawer()
  79. }
  80. }
  81. </script>

<mds-option label="未发布" value="0" />  string

<mds-option label="未发布" :value="0" /> number

排序

  1. <el-table :data="tableData" header-row-class-name="table-header" @sort-change="sortChange">
  2. ....
  3. </el-table>
  1. confirmpageQuery() {
  2. this.loading = true
  3. const params = {
  4. pageNum: this.pageInfo.currentPage,
  5. pageSize: this.pageInfo.pageSize,
  6. moduTyp: '',
  7. releStat: "",
  8. fuzzySearch: this.searchVal,
  9. updateStartDate: "",
  10. // updateEndDate: "",
  11. updateEndDate: "",
  12. ...this.filterData,
  13. ...this.sortProps
  14. }
  15. confirmpageQuery(params).then((res: any) => {
  16. if (res && res.code == 200) {
  17. this.pageInfo.total = res.data.totalElements
  18. this.tableData = res.data.data || []
  19. this.permissionMap = res.data.permissionMap || {}
  20. }
  21. }).catch((e: any) => {
  22. this.$message.error(e && e.msg)
  23. }).finally(() => {
  24. this.loading = false
  25. })
  26. }
  27. class YourClass {
  28. // 定义 sortProps 对象,用于存储排序属性的状态
  29. sortProps: any = {
  30. versionNumSort: '',
  31. releStatSort: '',
  32. updateDateSort: ''
  33. }
  34. // sortChange 方法用于处理排序变化
  35. sortChange(arguments: any) {
  36. const { column, prop, order } = arguments
  37. // 定义 orderVal 对象,用于存储排序方式的值(升序和降序)
  38. const orderVal: any = {
  39. ascending: 1,
  40. descending: 0
  41. }
  42. // 定义 propName 对象,用于映射排序属性和 sortProps 对象的属性名
  43. const propName: any = {
  44. versionNum: 'versionNumSort',
  45. releStat: 'releStatSort',
  46. updTm: 'updateDateSort'
  47. }
  48. // 将 sortProps 对象中所有属性的值初始化为空,以便重新设置排序状态
  49. for (let key in this.sortProps) {
  50. this.sortProps[key] = ''
  51. }
  52. // 根据传入的排序属性和排序方式,更新 sortProps 对象中对应的属性值
  53. this.sortProps[propName[prop]] = orderVal[order]
  54. // 调用 confirmpageQuery 方法,可能是用于触发其他逻辑或执行查询等操作
  55. this.confirmpageQuery()
  56. }
  57. // 定义 confirmpageQuery 方法,可能是其他逻辑处理的入口
  58. confirmpageQuery() {
  59. // 在这里执行其他逻辑或查询操作
  60. // ...
  61. }
  62. }

表格

  1. <el-table :data="tableData" header-row-class-name="table-header" @sort-change="sortChange">
  2. <!-- 展开 -->
  3. <el-table-column width="30" type="expand" class-name="expend-row">
  4. <!-- 自定义样式slot-scope="scope" {{ scope_sub.row.confmVersion }} -->
  5. <template slot-scope="scope">
  6. <el-table :data="scope.row.confmReleVOS" style="width: 100%;margin: 0;" class="inner-table">
  7. <!-- 缩进 -->
  8. <el-table-column width="30"></el-table-column>
  9. <el-table-column prop="confmVersion" label="版本号" width="120">
  10. <template slot-scope="scope_sub">
  11. <div>
  12. {{ scope_sub.row.confmVersion }}
  13. <span v-if="scope_sub.row.isCurrentVersion" class="version-current">当前版本</span>
  14. </div>
  15. </template>
  16. </el-table-column>
  17. <el-table-column prop="name" label="生效区间" width="220">
  18. <template slot-scope="scope_sub">
  19. {{ scope_sub.row.effectiveDateRange }}
  20. </template>
  21. </el-table-column>
  22. <el-table-column prop="releName" label="发布名称" />
  23. <!-- show-overflow-tooltip在用户将鼠标悬停在容器上时显示一个工具提示,以显示溢出的内容 -->
  24. <el-table-column prop="releDesc" label="发布说明" show-overflow-tooltip />
  25. <el-table-column label="操作" width="150">
  26. <template slot-scope="scope_sub">
  27. <!-- <span v-if="permissionMap.hasWorkbenchPageReleaseViewPer" class="table-operate" @click="toDetail(scope.row, scope_sub.row)">查看</span> -->
  28. <span class="table-operate" @click="toDetail(scope.row, scope_sub.row)">查看</span>
  29. </template>
  30. </el-table-column>
  31. </el-table>
  32. </template>
  33. </el-table-column>
  34. <el-table-column prop="confmNm" label="数据确认版本名称" min-width="120" show-overflow-tooltip />
  35. <el-table-column prop="moduTyp" label="模块" width="170" />
  36. <el-table-column prop="releStat" label="当前状态" sortable="custom" width="120">
  37. <template slot-scope="scope">
  38. <div :class="{ 'status-published': scope.row.releStat === 1, 'status-unpublished': scope.row.releStat === 0 }">
  39. {{ scope.row.releStatNm }}
  40. </div>
  41. <!-- <div class="status-published" v-if="scope.row.releStat === 1">{{ scope.row.releStatNm }}</div>
  42. <div class="status-unpublished" v-if="scope.row.releStat === 0">{{ scope.row.releStatNm }}</div> -->
  43. </template>
  44. </el-table-column>
  45. <el-table-column prop="versionNum" label="版本数" sortable="custom" width="90" />
  46. <el-table-column prop="creator" label="创建人" width="120" />
  47. <el-table-column prop="updTm" label="更新时间" width="180" sortable="custom" />
  48. <!-- <el-table-column label="操作" width="220">
  49. <template slot-scope="scope">
  50. <span v-if="permissionMap.hasWorkbenchPageConfigEditPer" class="table-operate" @click="toEdit(scope.row)">编辑</span>
  51. <span v-if="permissionMap.hasWorkbenchPageConfigReleasePer" class="table-operate" @click="handlePublish(scope.row)">{{ scope.row.releStat === 0 ? '发布' : scope.row.releStat === 1 ? '再次发布' : '' }}</span>
  52. <span v-if="permissionMap.hasWorkbenchPageConfigDeletePer" class="table-operate" @click="handleDelete(scope.row)">删除</span>
  53. </template>
  54. </el-table-column> -->
  55. <el-table-column label="操作" width="220">
  56. <template slot-scope="scope">
  57. <span class="table-operate" @click="toEdit(scope.row)">编辑</span>
  58. <span class="table-operate" @click="handlePublish(scope.row)">{{ scope.row.releStat === 0 ? '发布' : scope.row.releStat === 1 ? '再次发布' : '' }}</span>
  59. <span class="table-operate" @click="handleDelete(scope.row)">删除</span>
  60. </template>
  61. </el-table-column>
  62. </el-table>

自定义数据样式

  1. <el-table-column prop="releStat" label="当前状态" sortable="custom" width="120">
  2. <template slot-scope="scope">
  3. <div :class="{ 'status-published': scope.row.releStat === 1, 'status-unpublished': scope.row.releStat === 0 }">
  4. {{ scope.row.releStatNm }}
  5. </div>
  6. </el-table-column>

inner-table

分页

删除

loading

 

 添加slot=footer覆盖原有样式

 

default-modal

  1. <template>
  2. <mds-modal
  3. class="confirm-delete-modal"
  4. :class="{ 'confirm-delete-modal-warning': type === 'warning' }"
  5. :visibility="visibility"
  6. :title="title"
  7. :width="width"
  8. :show-close="false"
  9. >
  10. <div v-if="content" class="content">{{ content }}</div>
  11. <slot></slot>
  12. <span slot="footer" class="mds-dialog-footer">
  13. <mds-button @click="footActionClick('cancel')">{{ cancelText }}</mds-button>
  14. <mds-button
  15. type="primary"
  16. :loading="loading"
  17. @click="footActionClick('confirm')"
  18. >
  19. <mds-icon v-if="loading" type="line-sync" class="mds-btn-right" spin />
  20. {{ confirmText }}
  21. </mds-button>
  22. </span>
  23. </mds-modal>
  24. </template>
  25. <script lang="ts">
  26. import { Component, Prop, Vue, Watch } from 'vue-property-decorator'
  27. @Component({
  28. components: {}
  29. })
  30. export default class defaultModal extends Vue {
  31. @Prop({ required: true }) private visibility!: boolean
  32. // ! 表示非空断言,告诉 TypeScript 该属性不会为 null 或 undefined
  33. @Prop({ required: true }) private title!: string
  34. // ?: string 表示 content 是一个可选的属
  35. @Prop() private content?: string
  36. @Prop({ default: '420px' }) private width!: string
  37. @Prop({ default: false }) private showClose!: boolean
  38. @Prop({ default: '确定' }) private confirmText!: string
  39. @Prop({ default: '取消' }) private cancelText!: string
  40. @Prop({ default: 'normal' }) private type!: string
  41. @Prop({
  42. default: () => {
  43. return (cb: any) => {
  44. cb && cb()
  45. }
  46. }
  47. })
  48. private confirmCb!: any
  49. @Prop({
  50. default: () => {
  51. return (cb: any) => {
  52. cb && cb()
  53. }
  54. }
  55. })
  56. private cancelCb!: any
  57. private loading = false
  58. private loadingIns = {
  59. start: this.changeLoading.call(this, true),
  60. end: this.changeLoading.call(this, false)
  61. }
  62. private changeLoading(bool = false): any {
  63. return () => {
  64. this.loading = bool
  65. }
  66. }
  67. private footActionClick(type = 'cancel'): void {
  68. if (this.loading) return
  69. const cb = () => {
  70. this.$emit('update:visibility', false)
  71. }
  72. if (type === 'cancel') {
  73. this.cancelCb(cb, this.loadingIns)
  74. }
  75. if (type === 'confirm') {
  76. this.confirmCb(cb, this.loadingIns)
  77. }
  78. }
  79. private handleClose(done: any): void {
  80. if (this.loading) return
  81. this.$emit('update:visibility', false)
  82. }
  83. }
  84. </script>
  85. <style lang="scss" scoped>
  86. // ::v-deep .mds-modal-mask, .mds-modal-wrap {
  87. // z-index: 2000;
  88. // }
  89. .confirm-delete-modal {
  90. ::v-deep {
  91. .mds-modal-title {
  92. display: flex;
  93. align-content: center;
  94. // &::before {
  95. // content: '\EBD2';
  96. // color: #3370ff;
  97. // display: inline-block;
  98. // font-family: 'mdsicon';
  99. // font-size: 22px;
  100. // margin-right: 16px;
  101. // }
  102. }
  103. .mds-modal-bottom {
  104. border: none;
  105. }
  106. }
  107. .content {
  108. padding-left: 38px;
  109. }
  110. }
  111. .confirm-delete-modal-warning {
  112. // ::v-deep .mds-modal-title {
  113. // &::before {
  114. // content: '\EBC9';
  115. // color: #f80;
  116. // }
  117. // }
  118. .mds-dialog-footer {
  119. margin-top: 16px;
  120. font-size: 14px;
  121. text-align: right;
  122. // .mds-btn {
  123. // font-size: 12px;
  124. // height: 28px;
  125. // line-height: 20px;
  126. // min-width: 48px;
  127. // padding: 3px 7px;
  128. // color: #383c41;
  129. // &:hover {
  130. // background-color: #eee;
  131. // border-color: #d9d9d9;
  132. // }
  133. // &:last-child {
  134. // color: #f54a45;
  135. // border-color: #f54a45;
  136. // &:hover {
  137. // background-color: rgb(255, 233, 233);
  138. // }
  139. // }
  140. // }
  141. .mds-btn-loading {
  142. background-color: transparent;
  143. }
  144. }
  145. }
  146. ::v-deep .mds-modal-body {
  147. min-height: 0;
  148. }
  149. </style>
自定义元素的插槽-占位符
  1. <!-- 自定义元素定义 -->
  2. <custom-element>
  3. <h1><slot></slot></h1>
  4. <p>This is some default content.</p>
  5. </custom-element>
  6. <!-- 使用自定义元素 -->
  7. <custom-element>
  8. Hello, I am inserted into the slot!
  9. </custom-element>

 

  1. <!-- 删除二次确认弹窗 -->
  2. <default-modal :visibility.sync="defaultModalInfo.visibility" :type="defaultModalInfo.type"
  3. :title="defaultModalInfo.title" :content="defaultModalInfo.content" :confirm-text="defaultModalInfo.confirmText"
  4. :cancel-text="defaultModalInfo.cancelText" :confirm-cb="defaultModalInfo.confirmCb">
  5. <div>
  6. <mds-icon type="fill-solid-exclamation-circle" style="color:#e6a23c;font-size:18px" />
  7. 确定要删除数据吗?
  8. </div>
  9. </default-modal>
  10. // 删除
  11. handleDelete(row: any) {
  12. // 创建一个对象来设置模态框的信息
  13. this.defaultModalInfo = {
  14. visibility: true, // 设置模态框可见性为true,即显示模态框
  15. type: 'warning', // 设置模态框类型为警告,可以根据需要修改为其他类型
  16. title: '提示', // 设置模态框标题为'提示'
  17. content: '', // 设置模态框内容为空,可以根据需要填充具体的提示信息
  18. confirmText: '确定', // 设置确认按钮文本为'确定'
  19. cancelText: '取消', // 设置取消按钮文本为'取消'
  20. // @ts-ignore: 不可达代码错误(这里是为了忽略可能出现的编译错误,因为后面的 confirmCb 函数在当前环境下可能无法触发)
  21. confirmCb: (...args: any) => this.confirmDelete(row.id, ...args) // 设置确认按钮点击后的回调函数,传入当前行的id以及可能的其他参数
  22. };
  23. }
  24. // 确认删除
  25. private async confirmDelete(id: number, cb: any, loadingIns: any) {
  26. // 如果loadingIns存在并且具有start方法,则调用它,用于开始加载状态
  27. loadingIns && loadingIns.start && loadingIns.start();
  28. // 调用服务器端接口执行删除操作,传入id参数
  29. const res: any = await confirmpageDelete(id);
  30. // 如果loadingIns存在并且具有end方法,则调用它,用于结束加载状态
  31. loadingIns && loadingIns.end && loadingIns.end();
  32. // 如果服务器返回结果为空或者code不等于200,则删除失败,不做任何操作
  33. if (!res || res.code != 200) {
  34. // 可以根据需要,使用某种方式显示删除失败的提示信息,这里是注释掉的代码
  35. // this.$message.error(res && res.msg)
  36. return;
  37. }
  38. // 如果传入了回调函数cb,则执行回调函数
  39. cb && cb();
  40. // 使用消息框提示删除成功
  41. this.$message.success('删除成功');
  42. // 调用刷新列表的方法,以更新数据
  43. this.confirmpageQuery();
  44. }
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/641973
推荐阅读
相关标签
  

闽ICP备14008679号