久久久久av_欧美日韩一区二区在线_国产精品三区四区_日韩中字在线

12
返回列表 發帖
樓主: 鐵板魷魚燒

[已解決] 手機版表格顯示不全怎么辦?x3.5

6

主題

786

回帖

2171

積分

已臻大成

貢獻
136 點
金幣
85 個
11#
發表于 2024-8-20 17:44:14 | 只看Ta
或許你可以試試我這個方法------https://boonkiong.com/thread-3699-1-1.html
回復

使用道具 舉報

3

主題

23

回帖

33

積分

初學乍練

貢獻
0 點
金幣
5 個
QQ
12#
 樓主| 發表于 2024-8-20 18:42:34 | 只看Ta
文強 發表于 2024-8-20 17:44
或許你可以試試我這個方法------https://boonkiong.com/thread-3699-1-1.html

這個方法確實不錯,就是如果表格特別寬,全都都擠到這里,也很麻煩看不清,能夠水平往右邊滑動看到更多,其實效果更好,有沒有想法修改下
回復

使用道具 舉報

71

主題

465

回帖

691

積分

應用開發者

貢獻
14 點
金幣
26 個
QQ
13#
發表于 2024-8-20 22:34:08 | 只看Ta
在模板目錄下 如默認模板template/default/touch/forum/viewthread.htm
文件倒數第二行增加以下代碼(<!--{template common/footer}-->之前)




  1. <style>
  2.          
  3.         .message table td {
  4.                 padding: 5px;
  5.                 white-space: nowrap;
  6.                 overflow: hidden;
  7.                 text-overflow: ellipsis;
  8.                 border: 1px solid #ddd;
  9.         }
  10. </style>
  11. <script type="text/javascript">
  12.     function optimizeTables() {
  13.         var tables = document.querySelectorAll('.message table');
  14.         tables.forEach(function(table) {
  15.             // 設置表格樣式
  16.             table.style.width = '100%';
  17.             table.style.maxWidth = 'none'; // 移除最大寬度限制
  18.             table.style.tableLayout = 'fixed';
  19.             table.style.overflowX = 'auto';
  20.             table.style.display = 'block';
  21.             
  22.             var cells = table.rows[0].cells;
  23.             var cellCount = cells.length;
  24.             var minCellWidth = 100; // 最小列寬
  25.            
  26.             
  27.             // 設置每列的寬度
  28.             for (var i = 0; i < cellCount; i++) {
  29.                 cells[i].style.minWidth = minCellWidth + 'px';
  30.                 cells[i].style.width = (100 / cellCount) + '%';
  31.             }
  32.             
  33.             // 處理所有單元格
  34.             var allCells = table.getElementsByTagName('td');
  35.             for (var i = 0; i < allCells.length; i++) {
  36.                 allCells[i].style.whiteSpace = 'nowrap';
  37.                 allCells[i].style.overflow = 'hidden';
  38.                 allCells[i].style.textOverflow = 'ellipsis';
  39.             
  40.             }
  41.         });
  42.     }

  43.     // 在頁面加載完成和窗口大小改變時調用此函數
  44.     window.addEventListener('load', optimizeTables);
  45.     window.addEventListener('resize', optimizeTables);
  46.     </script>
復制代碼
回復

使用道具 舉報

6

主題

1032

回帖

1416

積分

應用開發者

貢獻
24 點
金幣
170 個
QQ
14#
發表于 2024-8-21 08:38:49 | 只看Ta
用編輯器自帶的試試看,如果不行的話,只能單獨對手機版做頁面優化。
回復

使用道具 舉報

3

主題

23

回帖

33

積分

初學乍練

貢獻
0 點
金幣
5 個
QQ
15#
 樓主| 發表于 2024-8-23 15:20:58 | 只看Ta
感謝各位的回答,我組織了一下,這個問題修改下代碼就好了,也希望官方可以把這個代碼整合進下一個版本更新!
我的站點測試鏈接:https://blog.haodaima.cn/forum.php?mod=viewthread&tid=1


我修改后的代碼,不僅可以實現手機上左右滑動,正確顯示表格狀態,左上角還有一個按鈕,支持一鍵復制表格內容,同時【全選表格】告知用戶復制了哪些,彈出提示框:“表格內容已復制”。每次點擊,提示框的顏色都不一樣,方便區分有時候復制錯表格再來復制這個,提醒當前復制的是哪個。


代碼如下:

1、打開文件/source/function/function_discuzcode.php

約438行左右,找到表格顯示函數,function parsetable,將其內容替換如下:意在修改表格顯示樣式,其中藍色部分為修改的部分,可整個函數復制替換,只替換藍色也行

  1. function parsetable($width, $bgcolor, $message) {
  2.         if(strpos($message, '[/tr]') === FALSE && strpos($message, '[/td]') === FALSE) {
  3.                 $rows = explode("\n", $message);
  4. <font color="#0000ff">                $s = !defined('IN_MOBILE') ? '<div style="overflow-x:auto;"><button class="copy-btn" onclick="copyTable(this)" style="margin-bottom: 10px;">一鍵復制</button><table cellspacing="0" class="t_table" '.
  5.                     ($width == '' ? NULL : 'style="width:'.$width.'"').
  6.                     ($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>') : '<div style="overflow-x:auto;"><button class="copy-btn" onclick="copyTable(this)" style="margin-bottom: 10px;">一鍵復制</button><table cellspacing="0" class="t_table">';</font>
  7.                 foreach($rows as $row) {
  8.                         $s .= '<tr><td>'.str_replace(array('\|', '|', '\n'), array('&#124;', '</td><td>', "\n"), $row).'</td></tr>';
  9.                 }
  10.                 $s .= '</table>';
  11.                 return $s;
  12.         } else {
  13.                 if(!preg_match("/^\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td([=\d,%]+)?\]/", $message) && !preg_match("/^<tr[^>]*?>\s*<td[^>]*?>/", $message)) {
  14.                         return str_replace('\"', '"', preg_replace("/\[tr(?:=([\(\)\s%,#\w]+))?\]|\[td([=\d,%]+)?\]|\[\/td\]|\[\/tr\]/", '', $message));
  15.                 }
  16.                 if(substr($width, -1) == '%') {
  17.                         $width = substr($width, 0, -1) <= 98 ? intval($width).'%' : '98%';
  18.                 } else {
  19.                         $width = intval($width);
  20.                         $width = $width ? ($width <= 560 ? $width.'px' : '98%') : '';
  21.                 }
  22.                 $message = preg_replace_callback("/\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td(?:=(\d{1,4}%?))?\]/i", 'parsetable_callback_parsetrtd_12', $message);
  23.                 $message = preg_replace_callback("/\[\/td\]\s*\[td(?:=(\d{1,4}%?))?\]/i", 'parsetable_callback_parsetrtd_1', $message);
  24.                 $message = preg_replace_callback("/\[tr(?:=([\(\)\s%,#\w]+))?\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/i", 'parsetable_callback_parsetrtd_1234', $message);
  25.                 $message = preg_replace_callback("/\[\/td\]\s*\[td(?:=(\d{1,2}),(\d{1,2})(?:,(\d{1,4}%?))?)?\]/i", 'parsetable_callback_parsetrtd_123', $message);
  26.                 $message = preg_replace("/\[\/td\]\s*\[\/tr\]\s*/i", '</td></tr>', $message);
  27. <font color="#0000ff">                return (!defined('IN_MOBILE') ? '<div style="overflow-x:auto;"><button class="copy-btn" onclick="copyTable(this)" style="margin-bottom: 10px;">一鍵復制</button><table cellspacing="0" class="t_table" '.
  28.                     ($width == '' ? NULL : 'style="width:'.$width.'"').
  29.                     ($bgcolor ? ' bgcolor="'.$bgcolor.'">' : '>') : '<div style="overflow-x:auto;"><button class="copy-btn" onclick="copyTable(this)" style="margin-bottom: 10px;">一鍵復制</button><table cellspacing="0" class="t_table">').
  30.                     str_replace('\"', '"', $message).'</table></div>';</font>
  31.         }
  32. }
復制代碼
2、修改電腦端樣式,使【框線顯示更清晰】【增加一鍵復制按鈕】

找到/template/default/common/header_common.htm

在文件底部添加如下代碼

  1. <script>
  2. var lastColorSchemeIndex = -1; // 初始化變量,記錄上一次使用的顏色索引,初始值為-1表示尚未選擇顏色

  3. function copyTable(button) {
  4.     var table = button.nextElementSibling; // 獲取按鈕下一個兄弟元素,即表格元素
  5.    
  6.     // 定義一個函數,用于選擇整個表格內容
  7.     function selectTable() {
  8.         if (window.getSelection) {
  9.             // 創建一個新的范圍對象
  10.             var range = document.createRange();
  11.             range.selectNode(table); // 將范圍設置為包含整個表格
  12.             window.getSelection().removeAllRanges(); // 清除當前的所有選區
  13.             window.getSelection().addRange(range); // 將新的范圍添加到選區中
  14.         } else if (document.selection) {
  15.             // 針對較舊的瀏覽器(如IE)的選擇邏輯
  16.             var range = document.body.createTextRange();
  17.             range.moveToElementText(table); // 將范圍設置為表格文本
  18.             range.select(); // 選擇范圍
  19.         }
  20.     }

  21.     // 首先選擇表格內容,以便后續操作
  22.     selectTable();

  23.     var rows = table.rows; // 獲取表格的所有行
  24.     var result = ''; // 初始化一個空字符串,用于存儲表格數據

  25.     // 遍歷表格的每一行
  26.     for (var i = 0; i < rows.length; i++) {
  27.         var cells = rows[i].cells; // 獲取當前行的所有單元格
  28.         // 遍歷當前行的每一個單元格
  29.         for (var j = 0; j < cells.length; j++) {
  30.             result += cells[j].innerText + (j === cells.length - 1 ? '' : '\t'); // 將單元格內容加入結果字符串,用制表符分隔
  31.         }
  32.         result += '\n'; // 每一行結束后,加入換行符
  33.     }

  34.     // 移除最后一個多余的換行符
  35.     if (result.endsWith('\n')) {
  36.         result = result.slice(0, -1);
  37.     }

  38.     // 將結果復制到剪貼板
  39.     var tempTextArea = document.createElement('textarea'); // 創建一個臨時的文本區域元素
  40.     tempTextArea.value = result; // 將表格內容賦值給臨時文本區域
  41.     document.body.appendChild(tempTextArea); // 將臨時文本區域添加到文檔中
  42.     tempTextArea.select(); // 選擇臨時文本區域的內容
  43.     document.execCommand('copy'); // 執行復制命令
  44.     document.body.removeChild(tempTextArea); // 復制完成后,移除臨時文本區域
  45.    
  46.     // 再次選擇表格,確保它在復制后被全選
  47.     selectTable();
  48.    
  49.     // 定義三種提示框顏色方案,包含背景色和文字顏色
  50.     var colorSchemes = [
  51.         { background: '#4CAF50', color: 'white' }, // 綠色背景,白色文字
  52.         { background: '#FF9800', color: 'black' }, // 橙色背景,黑色文字
  53.         { background: '#2196F3', color: 'white' }  // 藍色背景,白色文字
  54.     ];
  55.    
  56.     // 確保新選擇的顏色方案與上一次不同
  57.     var newColorSchemeIndex;
  58.     do {
  59.         newColorSchemeIndex = Math.floor(Math.random() * colorSchemes.length); // 隨機選擇一個顏色索引
  60.     } while (newColorSchemeIndex === lastColorSchemeIndex); // 如果新顏色與上一次相同,則重新選擇

  61.     lastColorSchemeIndex = newColorSchemeIndex; // 更新記錄的顏色索引為當前選擇的顏色
  62.     var selectedColorScheme = colorSchemes[newColorSchemeIndex]; // 獲取選中的顏色方案

  63.     // 創建一個提示框元素,并設置其樣式和文本內容
  64.     var alertBox = document.createElement('div');
  65.     alertBox.className = 'copy-alert'; // 設置提示框的CSS類
  66.     alertBox.textContent = "表格內容已復制!"; // 設置提示框顯示的文本
  67.     alertBox.style.backgroundColor = selectedColorScheme.background; // 應用隨機選擇的背景顏色
  68.     alertBox.style.color = selectedColorScheme.color; // 應用隨機選擇的文字顏色
  69.     document.body.appendChild(alertBox); // 將提示框添加到文檔中

  70.     // 讓提示框顯示
  71.     alertBox.style.display = 'block';

  72.     // 1秒后自動隱藏提示框并移除它
  73.     setTimeout(function() {
  74.         alertBox.style.display = 'none'; // 隱藏提示框
  75.         document.body.removeChild(alertBox); // 從文檔中移除提示框
  76.     }, 1000);
  77. }

  78. </script>

  79. <!--按鈕樣式-->
  80. <style>
  81. .copy-btn {
  82.     background: linear-gradient(45deg, #ff6b6b, #f94d6a); /* 漸變背景 */
  83.     border: none; /* 移除邊框 */
  84.     color: white; /* 白色文本 */
  85.     padding: 10px 20px; /* 按鈕內邊距 */
  86.     text-align: center; /* 文字居中 */
  87.     text-decoration: none; /* 移除下劃線 */
  88.     display: inline-block; /* 使按鈕在一行內 */
  89.     font-size: 14px; /* 字體大小 */
  90.     margin: 4px 2px; /* 外邊距 */
  91.     cursor: pointer; /* 鼠標指針樣式 */
  92.     border-radius: 8px; /* 圓角 */
  93.     transition: background 0.3s, transform 0.1s; /* 背景色和縮放效果漸變 */
  94.     box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* 添加陰影 */
  95. }

  96. .copy-btn:hover {
  97.     background: linear-gradient(45deg, #f94d6a, #ff6b6b); /* 懸停時漸變背景 */
  98. }

  99. .copy-btn:active {
  100.     transform: scale(0.95); /* 點擊時的縮放效果 */
  101.     box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2); /* 點擊時調整陰影 */
  102. }

  103. .copy-alert {
  104.     position: fixed;
  105.     top: 50%; /* 垂直居中 */
  106.     left: 50%; /* 水平居中 */
  107.     transform: translate(-50%, -50%); /* 將元素中心點移到正確的位置 */
  108.     background-color: #4CAF50; /* 綠色背景 */
  109.     color: white; /* 白色文本 */
  110.     padding: 10px 20px; /* 內邊距 */
  111.     border-radius: 5px; /* 圓角 */
  112.     box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); /* 添加陰影 */
  113.     z-index: 1000; /* 確保在最前面 */
  114.     font-size: 14px;
  115.     display: none; /* 初始狀態下隱藏 */
  116. }
  117. </style>

  118. <!--表格顯示框線,表格單行顯示-->
  119. <style>
  120. .t_table {
  121.     width: 100%; /* 設置表格的寬度為父容器的 100%,即表格會自動適應父容器的寬度 */
  122.     min-width: 600px; /* 設置表格的最小寬度為 600 像素,確保內容即使在父容器寬度較小時也能完整顯示 */
  123.     table-layout: auto; /* 設置表格布局為自動,即表格列的寬度會根據內容自動調整 */
  124. }
  125. .t_table td {
  126.     padding: 4px; /* 設置單元格內容與單元格邊框之間的內邊距為 4 像素 */
  127.     line-height: 1.1; /* 設置單元格內容的行高為 1.1 倍的字體大小,確保內容間距適中 */
  128.     border: 1px solid #afbeca; /* 設置單元格的邊框為 1 像素實線,顏色為 #afbeca(淺灰色) */
  129.     overflow: hidden; /* 當單元格內容過多時,超出部分會被隱藏,防止溢出影響布局 */
  130. }  
  131. </style>
復制代碼
3、修改手機端的,找到文件/template/default/touch/common/header.htm

將【2】的代碼復制進這個文件底部,</head>代碼之前,即可



回復

使用道具 舉報

322

主題

1341

回帖

1849

積分

已臻大成

貢獻
12 點
金幣
10 個
16#
發表于 2025-1-20 11:37:41 來自手機 | 只看Ta
好用,感謝
回復

使用道具 舉報

322

主題

1341

回帖

1849

積分

已臻大成

貢獻
12 點
金幣
10 個
17#
發表于 2025-1-20 11:57:44 | 只看Ta
1、打開文件/source/function/function_discuzcode.php   
下面的代碼好像不對 x3.5默認模板



回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

  • 關注公眾號
  • 有償服務微信
  • 有償服務QQ

手機版|小黑屋|Discuz! 官方交流社區 ( 皖ICP備16010102號 |皖公網安備34010302002376號 )|網站地圖|star

GMT+8, 2025-7-5 23:45 , Processed in 0.046585 second(s), 11 queries , Redis On.

Powered by Discuz! W1.0 Licensed

Cpoyright © 2001-2025 Discuz! Team.

關燈 在本版發帖
有償服務QQ
有償服務微信
返回頂部
快速回復 返回頂部 返回列表