a-table單元格指定合并以及表格雙擊編輯以及未填寫指定驗證功能

文章目錄

  • a-table單元格指定合并以及表格雙擊編輯以及未填寫指定驗證功能
    • 一、 a-table單元格指定合并
      • 1. a-table
      • 2. columns
      • 3. 圖例
    • 二、a-table 表格雙擊編輯以及未填寫驗證
      • 1. a-table
      • 2. js
      • 3. 圖例

a-table單元格指定合并以及表格雙擊編輯以及未填寫指定驗證功能

一、 a-table單元格指定合并

1. a-table

				<a-tableref="table":pagination="{position: ['none']}":columns="columns":dataSource="tableData":alert="false":row-key="(record) => record.id"bordered></a-table>

2. columns

columns.value = [{title: '序號',dataIndex: 'index',align: 'center',width: '300px',customRender: function ({ text, record, index }) {if (record.objectName === '單元測評結果(符合/部分符合/不符合/不適用)') {return record.objectName} else {return index + 1}},customCell: (data, index) => {if (data.objectName === '單元測評結果(符合/部分符合/不符合/不適用)') {return {colSpan: 2}} else {return { colSpan: 1 }}}},{title: '測評對象',dataIndex: 'objectName',align: 'center',width: '300px',customCell: (data, index) => {if (data.objectName === '單元測評結果(符合/部分符合/不符合/不適用)') {return {colSpan: 0}} else {return { colSpan: 1 }}}},{title: '測評指標符合情況(符合/部分符合/不符合/不適用)',dataIndex: 'content1',align: 'center',width: '300px',children: [{title: '身份鑒別',dataIndex: '9',align: 'center',width: '300px'},{title: '遠程管理通道安全',dataIndex: '10',align: 'center',width: '300px'},{title: '系統資源訪問控制信息完整性',dataIndex: '11',align: 'center',width: '300px'},{title: '重要信息資源安全標記完整性',dataIndex: '12',align: 'center',width: '300px'},{title: '日志記錄完整性',dataIndex: '13',align: 'center',width: '300px'},{title: '重要可執行程序完整性、重要可執行程序來源真實性',dataIndex: '14',align: 'center',width: '300px'}]}]

3. 圖例

在這里插入圖片描述

二、a-table 表格雙擊編輯以及未填寫驗證

1. a-table

		<a-tablestyle="width: 100%"bordered:dataSource="tableData"ref="selection":pagination="false":columns="columns":customRow="Rowclick":row-key="(record) => record.evaluationEnvironmentId":class="{ 'no-hover': disableHover }"><template #bodyCell="{ column, index, record }"><template v-if="column.key === 'handle'"><a-space><a-button type="primary" danger @click="onDelete(record, index)" :disabled="isReview"> 刪除 </a-button><a-buttontype="primary"@click="getModifications(record, index)":disabled="isReview"v-if="record.checkState == '0' || !record.checkState"style="background: rgb(183 175 175); border: none">后續修改</a-button><a-buttontype="primary"@click="getModifications(record, index)":disabled="isReview"v-if="record.checkState == '1'"style="background: #f88f5e; border: none">后續修改<CloseCircleFilled /></a-button></a-space></template></template></a-table>

2. js

子組件內容

//雙擊編輯

const Rowclick = (columns, index, record) => {return {onClick: (event) => {if (!isReview) {//isReview為驗證在什么條件下可以編輯/不可以編輯if (currentRowIndex.value != undefined) {if (currentRowIndex.value != index) {lastRowIndex.value = currentRowIndex.value}}currentRowIndex.value = indexconst cellElement = event.target.closest('td')if (cellElement) {currentColumnIndex.value = cellElement.cellIndex}}},onDblclick: (event) => {console.log(isReview,'isReview')if (!isReview) {if (lastRowIndex.value != undefined) {if (lastRowIndex.value != index) {if (cloneDataList.value[index]) {cloneDataList.value[index].editting = {}}}}const cellElement = event.target.closest('td')const dataIndex = props.columns[cellElement.cellIndex].keycloneDataList.value[index].editting = {}cloneDataList.value[index].editting[dataIndex] = truepasteStatus.value = false}}}}

//可以復制

const pasteInfo = (e) => {if (!isReview) {try {if (pasteStatus.value) {//獲得粘貼的文字var data = nullvar clipboardData = e.clipboardData // IEif (!clipboardData) {//chromeclipboardData = e.originalEvent.clipboardData}data = clipboardData.getData('Text')var rowStrArray = data.split('\n')rowsInfo.value = []for (var i = 0; i < rowStrArray.length - 1; i++) {var row = []var tdStrArray = rowStrArray[i].split('\t')for (var j = 0; j < tdStrArray.length; j++) {row.push(tdStrArray[j].replace('\r', ''))}rowsInfo.value.push(row)}let tableLength = props.tableData.lengthfor (var j = 0; j < rowsInfo.value.length; j++) {if (currentRowIndex.value + j >= tableLength) {addLine()}temp.value = JSON.parse(JSON.stringify(props.tableData[currentRowIndex.value + j]))let num = 0let numFlag = 0for (var key in props.emptyObj) {if (!rowsInfo.value[j][num]) {break}if (currentColumnIndex.value - 2 <= numFlag) {temp.value[key] = rowsInfo.value[j][num]if (temp.value.cellClassName && temp.value.cellClassName[key]) {delete temp.value.cellClassName[key]}num = num + 1}numFlag = numFlag + 1}// this.$set(tableData.value, currentRowIndex.value+j, temp.value)props.tableData[currentRowIndex.value + j] = temp.value}window.localStorage.setItem('editTableLength', props.tableData.length)cloneDataList.value = JSON.parse(JSON.stringify(props.tableData)).map((item) => {item.editting = falsereturn item})}} catch (err) {message.error({content: '請選擇復制位置'})}}}

//獲取tableData

	const init = () => {cloneDataList.value = JSON.parse(JSON.stringify(props.tableData)).map((item, index) => {item.editting = falsereturn item})props.columns.forEach((item, index) => {// if (item.editable) {// $set(item, 'renderHeader', (h, params) => {// return h('div', [h('span', {//   domProps: {//     innerHTML: item.title//   },// }),// ])// });// }//如果含有editable屬性并且為trueif (item.editable) {item.customRender = function ({ text, record, index, column }) {var currentRow = cloneDataList.value[index]if (!currentRow.editting[item.key]) {if (item.date) {return h('span', currentRow[item.key])}// 下拉類型中value與label不一致時單獨渲染if (item.option) {// 我這里為了簡單的判斷了第一個元素為object的情況,其實最好用every來判斷所有元素if (typeof item.option[0] === 'object') {if (item.multiple) {let arr1 = [],arrif (typeof currentRow[item.key] == 'string' && currentRow[item.key])arr = currentRow[item.key].split(',')else arr = currentRow[item.key]arr &&arr.length > 0 &&arr.forEach((optionItem) => {// arr1.push(item.option.find(findObjectInOption(optionItem)).label)arr1.push(item.option.find(findObjectInOption(optionItem))? item.option.find(findObjectInOption(optionItem)).label: optionItem)})return h('span', {}, arr1.join())} else {// let params = item.option.find(findObjectInOption(currentRow[item.key])) ? item.option.find(findObjectInOption(currentRow[item.key])).label : '請選擇'let params = item.option.find(findObjectInOption(currentRow[item.key]))? item.option.find(findObjectInOption(currentRow[item.key])).label: currentRow[item.key]return h('span', {}, params)}}}return h('span', currentRow[item.key])} else {if (item.option) {//  && typeof currentRow[column.key] == 'string'if (item.multiple) {// let arr = currentRow[column.key].split(',')let arr = currentRow[column.key]if (arr == '請選擇') {arr = undefined}return h(Select, {placeholder: '請選擇',value: arr,options: item.option,mode: 'multiple',style: { width: '100%' },onChange: (value) => {// if(!value){//   currentRow[column.key] ='請選擇'// }else{//   currentRow[column.key] = value// }currentRow[column.key] = valuesaveData(currentRow, index, column.key, value)},onClear: function () {}})} else {return h(Select, {placeholder: '請選擇',value: currentRow[column.key],options: item.option,style: { width: '100%' },onChange: (value) => {if (value.length == 0) {currentRow[column.key] = '請選擇'} else {currentRow[column.key] = value}saveData(currentRow, index, column.key, value)}})}} else if (item.date) {//如果含有date屬性return h('DatePicker', {props: {type: item.date.split('_')[0] || 'date',clearable: false,value: currentRow[params.column.key]},on: {'on-change': function (value) {self.$set(currentRow, params.column.key, value)}}})} else {return h(Input, {placeholder: '請輸入',// value: currentRow[column.key] = '未填寫'? undefined:currentRow[column.key],value: currentRow[column.key],onChange: (event) => {currentRow[column.key] = event.target.valuesaveData(currentRow, index, column.key, event.target.value)},onBlur: (event) => {cloneDataList.value[index].editting = {}if (event.target.value == '') {currentRow[column.key] = '未填寫'}saveData(currentRow, index, column.key, event.target.value)}})}}}} else {if (item.key == 'orderNum') {item.customRender = function ({ text, record, index }) {return index + 1}}}// 使用$set 可以觸發視圖更新// 如果含有titleHtml屬性 將其值填入表頭if (item.children) {item.children.forEach((child) => {if (child.editable) {child.render = function (h, params) {var currentRow = self.cloneDataList[params.index]// 非編輯狀態if (!currentRow.editting) {// 日期類型單獨 渲染(利用工具暴力的formatDate格式化日期)if (child.date) {// return h('span', self.utils.formatDate(currentRow[item.key], item.date.split('_')[1]))return h('span', currentRow[child.key])}// 下拉類型中value與label不一致時單獨渲染if (child.option) {// 我這里為了簡單的判斷了第一個元素為object的情況,其實最好用every來判斷所有元素if (typeof child.option[0] === 'object') {let params = child.option.find(findObjectInOption(currentRow[child.key]))? child.option.find(findObjectInOption(currentRow[child.key])).label: currentRow[child.key]return h('span', {}, params)}}return h('span', currentRow[child.key])} else {// 編輯狀態//如果含有option屬性if (child.option) {return h('Select',{props: {// ***重點***:  這里要寫currentRow[params.column.key],綁定的是cloneDataList里的數據value: currentRow[params.column.key],transfer: true,filterable: true},on: {'on-change': function (value) {self.$set(currentRow, params.column.key, value)}}},child.option.map(function (child) {return h('Option',{props: {value: child.value,label: child.label}},child.label)}))} else if (child.date) {//如果含有date屬性return h('DatePicker', {props: {type: child.date.split('_')[0] || 'date',clearable: false,value: currentRow[params.column.key]},on: {'on-change': function (value) {self.$set(currentRow, params.column.key, value)}}})} else {return h('input', {props: {// type類型也是自定的屬性type: child.input || 'text',// rows只有在input 為textarea時才會起作用rows: 3,// disabled: (params.row.type == '1' || params.row.type == '2') && (child.key == 'evaluationtDocumentsName' || child.key == 'content') ? true : false,value: currentRow[params.column.key],placeholder: child.placeholder ? item.placeholder : ''},on: {'on-change'(event) {self.$set(currentRow, params.column.key, event.target.value)}}})}}}}})}})}

中間組件
//editTable

		<editTable:emptyObj="emptyObj":columns="columns"ref="editTables":tableData="tableData":reviewShow="reviewShow"v-if="refresh_2"></editTable>

//消息保存驗證

	const getFormData = async () => {let flag = falsesubDataList.value = []let saveFlag = true// 創建一個 Promise 數組來處理異步操作const promises = []tableData.value.forEach((item, index) => {//判斷多出來的一行保存的時候不保存最后一行if (tableData.value.length - 1 == index && JSON.stringify(item) == JSON.stringify(emptyObj.value)) {console.log('空白行')} else {item.cellClassName = {};item.evaluationId = route.query.evaluationIditem.evaluationInformationId = route.query.evaluationInformationIdfor (var key in item) {if (emptyObj.value.hasOwnProperty(key)) {if ((item[key] === '' || item[key] === '未填寫' || item[key] === '請選擇') && key != 'remark') {item.cellClassName[key] = 'demo-table-info-cell-name'columns.value.forEach((item_1, index_1) => {if (item_1.key == key)columns.value[index_1].customCell = (record, rowIndex) => {return {class:record[item_1.key] == '請選擇' || record[item_1.key] == '未填寫'? 'demo-table-info-cell-name': ''}}})}// 重要程度if (key === 'levels') {let levelsFlag = falsefor (var i = 0; i < columns.value[3].option.length; i++) {if (columns.value[3].option[i].label == item[key] || columns.value[3].option[i].value == item[key]) {item[key] = columns.value[3].option[i].valuelevelsFlag = truebreak}}if (!levelsFlag) {columns.value.forEach((item_1, index_1) => {if (item_1.option) {columns.value[index_1].customCell = (record, rowIndex) => {// 遍歷 item_1.option 數組的每一項for (let i = 0; i < item_1.option.length; i++) {const currentOption = item_1.option[i]// 檢查條件并返回相應的 classif (record.levels == currentOption.label || record.levels == currentOption.value) {levelsFlag = trueitem[key] = currentOption.valuereturn {class: ''}}}// 如果沒有匹配項,返回默認的 classreturn { class: 'demo-table-info-cell-name' }}}})saveFlag = false}}}}if (Object.keys(item.cellClassName).length == 0) {delete item.cellClassNamelet processData = JSON.parse(JSON.stringify(item))subDataList.value.push(processData)} else {saveFlag = false}}})console.log(saveFlag, 'saveFlag3')if (!saveFlag) {editTables.value.init()} else {subDataList.value.push(...store.state.isopreservation.deleteList)store.commit('resetDeleteList')const res = await bizEnvironmentApi.saveEnvironmentList(subDataList.value)if (res == null) {flag = true}}return flag}

父組件

//調用中間組件方法
let flag = await researchSysForms.value.getFormData() 

3. 圖例

在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/diannao/35613.shtml
繁體地址,請注明出處:http://hk.pswp.cn/diannao/35613.shtml
英文地址,請注明出處:http://en.pswp.cn/diannao/35613.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

從零開始精通Onvif之加密與認證

&#x1f4a1; 如果想閱讀最新的文章&#xff0c;或者有技術問題需要交流和溝通&#xff0c;可搜索并關注微信公眾號“希望睿智”。 概述 安全是Onvif規范的核心部分&#xff0c;它涵蓋了加密和認證兩大領域。在Onvif標準下&#xff0c;安全措施主要包括&#xff1a;設備訪問控…

大模型AI技術實現語言規范練習

人工智能技術可以為語言規范練習提供多種有效的解決方案&#xff0c;幫助學習者更有效地掌握語言規范。以下是一些常見的應用場景。北京木奇移動技術有限公司&#xff0c;專業的軟件外包開發公司&#xff0c;歡迎交流合作。 1. 智能糾錯 利用自然語言處理技術&#xff0c;可以…

DC/AC電源模塊一種效率與可靠性兼備的能源轉換解決方案

DC/AC電源模塊都是一種效率與可靠性兼備的能源轉換解決方案 DC/AC電源模塊是一種能夠將直流電源&#xff08;DC&#xff09;轉換為交流電源&#xff08;AC&#xff09;的設備。它在現代電子設備中扮演著非常重要的角色&#xff0c;因為許多設備需要交流電源才能正常運行。無論…

樹形結構的勾選、取消勾選、刪除、清空已選、回顯、禁用

樹形結構的勾選、取消勾選、刪除、清空已選、回顯、禁用 基本頁面&#xff1a; 分為上傳文件和編輯的頁面 代碼實現要點&#xff1a; 上傳文件頁面&#xff1a; 點開選擇范圍彈窗&#xff0c;三個radio單選框都為可選狀態&#xff0c;默認顯示的是第一個單選框&#xff08;按…

開源C++版AI畫圖大模型框架stable-diffusion.cpp開發使用初體驗

stable-diffusion.cpp是一個C編寫的輕量級開源類AIGC大模型框架&#xff0c;可以支持在消費級普通設備上本地部署運行大模型進行AI畫圖&#xff0c;以及作為依賴庫集成的到應用程序中提供類似于網頁版stable-diffusion的功能。 以下基于stable-diffusion.cpp的源碼利用C api來…

人工智能的未來:暢想智能新時代

人工智能正在改變我們的世界&#xff0c;它將帶我們走向何方&#xff1f; 著名神經科學家、Numenta 公司創始人杰夫?霍金斯 Jeff Hawkins 在其著作《人工智能的未來》中&#xff0c;描繪了一幅人工智能發展的光明圖景。他認為&#xff0c;人工智能將超越人類智能&#xff0c;…

理解Gobrs-Async相對于CompletableFuture的優勢

Gobrs-Async框架針對復雜應用場景下的異步任務編排&#xff0c;提供了一些傳統Future或CompletableFuture所不具備的特性和能力&#xff0c;以下是它能夠解決的問題和相對于CompletableFuture的優勢&#xff1a; 1. **全鏈路異常回調**&#xff1a; - Gobrs-Async允許為任務…

關于地圖點擊的操作

_this.map.dragging.disable(); //地圖拖拽 _this.map.doubleClickZoom.disable(); //禁止雙擊放大地圖 _this.map.scrollWheelZoom.disable(); //禁止鼠標滑輪滾動放大縮小地圖 _this.map.dragging.enable(); //e…

備份和鏡像TrinityCore

相比重新安裝&#xff0c;省去了編譯的過程&#xff0c;同時還能保留以前的人物、裝備等。 注意&#xff0c;若不想重新編譯安裝&#xff0c;則需要創建一樣的目錄、賬戶等&#xff0c;以減少不必要的麻煩。 首先備份數據: mysql備份和導入方法見&#xff1a;使用dump備份my…

視覺與味蕾的交響:紅酒與藝術的無界狂歡,震撼你的感官世界

在浩瀚的藝術海洋中&#xff0c;紅酒以其不同的魅力&#xff0c;成為了一種跨界整合的媒介。當雷盛紅酒與藝術相遇&#xff0c;它們共同呈現出一場特別的視覺盛宴&#xff0c;讓人沉醉在色彩與光影的交織中&#xff0c;感受紅酒與藝術的無界碰撞。 雷盛紅酒&#xff0c;宛如一件…

AI作畫Prompt不會寫?Amazon Bedrock Claude3.5來幫忙

最新上線的Claude3.5 Sonnet按照官方介紹的數據來看&#xff0c;在多方面超越了CPT-4o&#xff0c;是迄今為止最智能的模型。 而跟上一個版本相比&#xff0c;速度是Claude 3 Opus的兩倍&#xff0c;成本只有其五分之一。 Claude3.5 Sonnet不僅擅長解釋圖表、圖形或者從不完…

vue3中子組件調用父組件事件

在 Vue 3 中&#xff0c;子組件調用父組件的事件&#xff08;或方法&#xff09;的方式與 Vue 2 類似&#xff0c;但 Vue 3 引入了 Composition API&#xff0c;這可能會改變你組織代碼的方式。不過&#xff0c;基本的通信機制——通過自定義事件 ($emit) 通知父組件——仍然保…

總結:DataX

一、介紹 本文主要介紹DataX的安裝與使用。 二、安裝 安裝&#xff1a;DataX/userGuid.md at master alibaba/DataX GitHub 六、案例 實現從MySQL同步數據到HDFS&#xff0c;然后使用Hive進行聚合計算并將結果存儲回MySQL。 步驟2&#xff1a;使用DataX同步MySQL數據到H…

Day28:回溯法 491.遞增子序列 46.全排列 47.全排列 II 332.重新安排行程 51. N皇后 37. 解數獨

491. 非遞減子序列 給你一個整數數組 nums &#xff0c;找出并返回所有該數組中不同的遞增子序列&#xff0c;遞增子序列中 至少有兩個元素 。你可以按 任意順序 返回答案。 數組中可能含有重復元素&#xff0c;如出現兩個整數相等&#xff0c;也可以視作遞增序列的一種特殊情…

Atcoder ABC359E Water Tank 題解

題目傳送門 題解 分析 分類討論。 記第 i i i 個答案為 a n s i 1 ans_i1 ansi?1。 第 i i i 個數就是目前的最大值。 顯然&#xff0c; a n s i h i i ans_ih_i \times i ansi?hi?i。第 i i i 個數就是目前的最大值。 記 l a s t i last_i lasti? 為 i i i …

網絡安全學習路線圖(2024版詳解)

近期&#xff0c;大家在網上對于網絡安全討論比較多&#xff0c;想要學習的人也不少&#xff0c;但是需要學習哪些內容&#xff0c;按照什么順序去學習呢&#xff1f;其實我們已經出國多版本的網絡安全學習路線圖&#xff0c;一直以來效果也比較不錯&#xff0c;本次我們針對市…

Java中多態的實現原理解析

Java中多態的實現原理解析 大家好&#xff0c;我是免費搭建查券返利機器人省錢賺傭金就用微賺淘客系統3.0的小編&#xff0c;也是冬天不穿秋褲&#xff0c;天冷也要風度的程序猿&#xff01;在本文中&#xff0c;我們將深入探討Java中多態的實現原理及其應用。多態是面向對象編…

centos中查看服務的日志

在CentOS中查看服務的日志通常涉及查看系統日志文件&#xff0c;這些文件通常位于/var/log/目錄下。不同的服務可能會有不同的日志文件。以下是一些常見的日志文件和查看它們的方法&#xff1a; 1. **系統日志**&#xff1a;系統日志通常存儲在/var/log/messages或/var/log/sy…

學會python——生成日志信息(python實例十二)

目錄 1、認識Python 2、環境與工具 2.1 python環境 2.2 Visual Studio Code編譯 3、生成日志信息 3.1 代碼構思 3.2 代碼示例 3.3 運行結果 4、總結 1、認識Python Python 是一個高層次的結合了解釋性、編譯性、互動性和面向對象的腳本語言。 Python 的設計具有很強的…

MySQL serverTimezone=UTC

在數據庫連接字符串中使用 serverTimezoneUTC 是一個常見的配置選項&#xff0c;特別是當數據庫服務器和應用程序服務器位于不同的時區時。這個選項指定了數據庫服務器應當使用的時區&#xff0c;以確保日期和時間數據在客戶端和服務器之間正確傳輸和處理。 UTC&#xff08;協…