• 记录vue开发实例


    封装的表格组件

    1. <template>
    2. <div>
    3. <div style="width: 100%" v-if="showList">
    4. <el-table v-loading.lock="loading" :data="dataList"
    5. :header-cell-style="{background: '#F2FCFE',fontSize: '14px',color: '#50606D'}"
    6. :row-style="{ height: '80px' }" class="menu_table"
    7. height="550">
    8. <el-table-column label="序号" type="index" width="80"></el-table-column>
    9. <el-table-column width="1"></el-table-column>
    10. <li v-for="(item,index) in settingOpts" :key="index">
    11. <el-table-column :key="Math.random()" :width="item.width" :fixed="item.fixed" :label="item.label">
    12. <template slot-scope="scope">
    13. <span v-if="item.isDisplay && item.isDisplay === true">
    14. {{
    15. (scope.row[item.id] && scope.row[item.id] != null && scope.row[item.id] != "") ? scope.row[item.id] : "--"
    16. }}
    17. </span>
    18. <span v-if="item.isNeedMethod && item.isNeedMethod === true">
    19. {{ $parent.findMethod(item.methodName, scope.row[item.id]) }}
    20. </span>
    21. <span v-if="item.isStatus && item.isStatus === true">
    22. {{ $parent.findMethod(item.statusMethodName,scope.row[item.id]) }}
    23. </span>
    24. <span v-if="item.isSpecialStatus && item.isSpecialStatus === true" :class="$parent.findMethod(item.specialClass,scope.row)">
    25. {{ $parent.findMethod(item.specialMethod,scope.row) }}
    26. </span>
    27. <span v-if="item.isNeedBack && item.isNeedBack === true" :class="$parent.findMethod(item.classMethod,scope.row)">
    28. {{ scope.row[item.displayName] }}
    29. </span>
    30. <div v-if="item.isSwitch && item.isSwitch === true">
    31. <el-switch :value="scope.row[item.id].val" @input="$parent.findMethod(item.switchInfo.switchMethod,scope.row)" :active-value="item.switchInfo.activeVal" :inactive-value="item.switchInfo.inactiveVal" :active-color="item.switchInfo.activeColor" :inactive-color="item.switchInfo.inactiveColor">
    32. </el-switch>
    33. </div>
    34. <div v-if="item.isImg && item.isImg === true">
    35. <p v-if="(!scope.row[item.id] || scope.row[item.id] == null || scope.row[item.id].length== '')">暂无人脸</p>
    36. <el-popover v-else aria-placeholder="top-start" trigger="hover">
    37. <div class="row_reserve">
    38. <img class="big-mig" :src="scope.row[item.id]">
    39. </div>
    40. <div slot="reference">
    41. <img style="width: 50px;height: 50px;" :src="scope.row[item.id]">
    42. </div>
    43. </el-popover>
    44. </div>
    45. <div v-if="item.isOperation && item.isOperation === true" class="flex jc-sa">
    46. <div v-for="(child,index) in item.operationOpts" :key="index" v-if="showOperation(child,scope)" style="color: #0080F7; cursor: pointer">
    47. <span @click="$parent.findMethod(child.method,scope.row)">
    48. {{ child.isNeedSpecial && child.isNeedSpecial === true ? $parent.findMethod(child.specialDisplay,scope.row) : child.name}}
    49. </span>
    50. </div>
    51. </div>
    52. </template>
    53. </el-table-column>
    54. </li>
    55. <template slot="empty">
    56. <div class="aic mt-20 mb-20">
    57. <img src="@/assets/empty.png" style="width: 45px; height: 36px" alt="" />
    58. <p style="margin: 0;font-size: 14px;height: 16px;line-height: 16px;color: #aba9bb;">暂无数据</p>
    59. </div>
    60. </template>
    61. </el-table>
    62. </div>
    63. </div>
    64. </template>
    65. <script>
    66. /*
    67. 项目列表参数属性详解
    68. * id String 用于关联props的属性名称
    69. * label String table中展示的列名
    70. * fixed Boolean/String 是否固定列,true默认左固定,可接收left或right
    71. * isDisplay Boolean 该属性是否可以直接用于展示
    72. * isNeedMethod Boolean 该属性是否需要经过自定义加工
    73. * methodName String/Object 自定义加工方法,若isNeedMethod为true,则须提供方法名称,不需要就默认null。
    74. * isStatus Boolean 该属性是否为状态值
    75. * statusMethodName String 目前状态的返回值在各列表中不统一,情况多样,所以单独提供一个加工方法。
    76. * isSpecialStatus Boolean 该状态是否需要特殊展示
    77. * specialClass String 特殊展示时的样式
    78. * specialMethod String 特殊展示时的方法(有些可能需要特殊处理)
    79. * isSwitch Boolean 是否为Switch开关类型
    80. * switchInfo Object switch开关需要用到的信息(激活值、颜色等),可参考客户(customer)模块
    81. Eg:switchInfo: {
    82. activeVal: "0",
    83. inactiveVal: "1",
    84. activeColor: "#13ce66",
    85. inactiveColor: "#DCDFE6",
    86. switchMethod: "updateCustomerStatus",
    87. },
    88. * isOperation Boolean 是否为操作列
    89. * operationOpts Array 操作列所需要的方法、展示名称、是否需要条件筛选及筛选条件,可参考访客(visitor)模块
    90. operationOpts:[
    91. {
    92. method String 操作列关联方法名
    93. name String 操作列名称
    94. isCondition Boolean 该操作是否需要展示条件
    95. condition Function 展示条件函数
    96. isNeedSpecial Boolean 该操作是否需要特殊展示(如操作名称随状态值进行改变)
    97. specialDisplay String 进行特殊展示的方法名
    98. }
    99. ]
    100. Eg: operationOpts: [
    101. {
    102. method: "auditVisitor",
    103. name: "审核",
    104. isCondition:true,
    105. condition:function(data){
    106. return data.status == 0
    107. }
    108. },
    109. {
    110. method: "editVisitor",
    111. name: "编辑",
    112. isCondition:true,
    113. condition:function(data){
    114. return data.status != 1
    115. }
    116. },
    117. },
    118. ],
    119. * isImg Boolean 是否为图片
    120. * isNeedBack Boolean 字段是否需要背景
    121. * classMethod String 切换样式的方法
    122. * displayName String 属性展示名(有些列需要用到两个属性,此处填写所需要用到的另一个属性key)
    123. */
    124. export default {
    125. name: "TableList",
    126. props: {
    127. dataList: {
    128. type: Array,
    129. required: true,
    130. },
    131. showList: {
    132. type: Boolean,
    133. required: true,
    134. },
    135. loading: {
    136. type: Boolean,
    137. required: true,
    138. },
    139. settingOpts: {
    140. type: Array,
    141. required: true,
    142. },
    143. },
    144. data() {
    145. return {};
    146. },
    147. methods: {
    148. showOperation(child, scope) {
    149. if (child.isCondition && child.isCondition === true) {
    150. return child.condition(scope.row);
    151. } else {
    152. return true;
    153. }
    154. },
    155. },
    156. created() {},
    157. };
    158. </script>
    159. <style lang="less" scoped>
    160. .menu_table {
    161. width: 98%;
    162. margin: 0 auto;
    163. margin-top: 20px;
    164. }
    165. div::-webkit-scrollbar {
    166. // 直接修改样式就可以了
    167. width: 8px;
    168. display: none;
    169. }
    170. // 滚动条
    171. ::-webkit-scrollbar {
    172. width: 40px;
    173. // background-color: red;
    174. }
    175. // 滚动条轨道
    176. ::-webkit-scrollbar-track {
    177. width: 40px;
    178. border-radius: 40px;
    179. background-color: #f4f8f7;
    180. }
    181. // 滚动条滑块
    182. ::-webkit-scrollbar-thumb {
    183. border: 5px solid #c1c1c1;
    184. border-radius: 40px;
    185. // background-color: yellow;
    186. }
    187. .connect {
    188. padding-left: 10px;
    189. padding-right: 10px;
    190. border-radius: 4px;
    191. background-color: #d6edff;
    192. }
    193. .gateway {
    194. padding-left: 10px;
    195. padding-right: 10px;
    196. border-radius: 4px;
    197. background-color: #ffdde0;
    198. }
    199. .gatewaySon {
    200. padding-left: 10px;
    201. padding-right: 10px;
    202. border-radius: 4px;
    203. background-color: #ffe8cb;
    204. }
    205. .open {
    206. color: #16dbcc;
    207. }
    208. .close {
    209. color: #e52a44;
    210. }
    211. </style>
    212.  引入使用

       

       element组件fixed="right" 表格错位

       解决方法

      1,

      2,

      3,

       通过数组数量循环input标签数量填写表单

      paramsInfo.fieldList的值

      targetDataList的值

       表单循环targetDataList获取 label值(即有多少个input标签的生成),表单填写的内容绑定在 paramsInfo.fieldList[index].fieldValue

      1. <el-form-item v-for="(column, index) in targetDataList" :key="index" :label="column.fieldDesc">
      2. <el-input :id="column.targetId"
      3. v-model.trim="paramsInfo.fieldList[index].fieldValue"
      4. :type="column.fieldName"
      5. style="width: 100%;"></el-input>
      6. </el-form-item>

       根据表头获取输入框数量

       根据表头的数量,新增的输入框数量

      1. //增加按钮
      2. addBtn() {
      3. // 检查 scopeBranchLists 不为空且包含 fieldName 属性
      4. if (Array.isArray(this.scopeBranchLists) && this.scopeBranchLists.length > 0) {
      5. // 使用 map 函数从 scopeBranchLists 中提取 fieldName 值
      6. //fieldNames = ['index_name', 'dept_name', 'comment', 'dept_type', 'options', 'unit', 'source_priority']
      7. // let fieldNames = this.scopeBranchLists.reduce((acc, item) => {
      8. // acc[item.fieldName] = '';
      9. // return acc;
      10. // }, {});
      11. const fieldNames = this.scopeBranchLists.map(item => item.fieldName);
      12. var fieldNamesObj = {};
      13. for (var i = 0; i < fieldNames.length; i++) {
      14. fieldNamesObj[fieldNames[i]] = null;
      15. }
      16. //this.formData = fieldNamesObj
      17. this.rows.push(fieldNamesObj);
      18. }
      19. },

       表头数据 

      {{ item.fieldDesc }}

       生成的input框数量(5个表头,生成对应五个输入框 为一个对象,最后放入rows数组)

      完整代码

      1. <div>
      2. <div style="display: flex;padding-top: 3px;padding-bottom: 8px;
      3. border-bottom: 1px solid #ccc;background-color: #f2fcfe; color: #50606d">
      4. <div v-for="(item, index) in scopeBranchLists" :key="index" style="margin-right: 3%;width: 140px;">
      5. {{ item.fieldDesc }}
      6. </div>
      7. </div>
      8. <table>
      9. <tr v-for="(obj, rowIndex) in rows" :key="rowIndex">
      10. <td
      11. style="display: flex;justify-content: space-between;padding-bottom: 20px; border-bottom: 1px solid #e4e7ed;">
      12. <el-input
      13. v-for="(value, key) in obj"
      14. :key="key"
      15. v-model.trim="obj[key]"
      16. style="margin-right: 28px;
      17. margin-top: 5px;
      18. height: 30px;
      19. width: 140px;
      20. "
      21. type="text"
      22. />
      23. <div style="width: 4%;margin-top: 10px">
      24. <img src="../../../assets/cancel.png" style="width: 18px;height: 18px;cursor: pointer;"
      25. @click="deleteDict(rowIndex)"/>
      26. </div>
      27. </td>
      28. </tr>
      29. </table>
      30. </div>

    213. 相关阅读:
      Springboot音乐播放小程序的设计与实现毕业设计-附源码191730
      【2021最新版】Spring Cloud面试题总结(35道题含答案解析)
      写给正在互联网经历孤独和迷茫的你
      全国职业技能大赛云计算--高职组赛题卷②(私有云)
      linux中 删除指定行多行sed命令
      内核初始化的过程
      中国核动力研究设计院使用 DolphinDB 替换 MySQL 实时监控仪表
      有哪些值得推荐的优秀 HTML&CSS 网站前端设计的网络资源(博客、论坛)?
      软件设计师学习笔记11-磁盘管理+IO管理软件+文件管理+作业管理
      关于Flume-Kafka-Flume的模式进行数据采集操作
    214. 原文地址:https://blog.csdn.net/Tel_17674647975/article/details/133632017