Showing
2 changed files
with
132 additions
and
1 deletions
| 1 | /* | 1 | /* |
| 2 | + * @Date: 2024-07-31 17:19:25 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2024-09-05 17:08:08 | ||
| 5 | + * @FilePath: /data-table/src/utils/tools.js | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | + */ | ||
| 8 | +/* | ||
| 2 | * @Date: 2022-04-18 15:59:42 | 9 | * @Date: 2022-04-18 15:59:42 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 10 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | * @LastEditTime: 2023-02-24 16:13:06 | 11 | * @LastEditTime: 2023-02-24 16:13:06 |
| ... | @@ -125,6 +132,69 @@ const stringifyQuery = (params) => { | ... | @@ -125,6 +132,69 @@ const stringifyQuery = (params) => { |
| 125 | return '?' + queryString.join('&'); | 132 | return '?' + queryString.join('&'); |
| 126 | }; | 133 | }; |
| 127 | 134 | ||
| 135 | +// 美化打印实现方法 | ||
| 136 | +const prettyLog = () => { | ||
| 137 | + const isProduction = import.meta.env.MODE === 'production'; | ||
| 138 | + | ||
| 139 | + const isEmpty = (value) => { | ||
| 140 | + return value == null || value === undefined || value === ''; | ||
| 141 | + }; | ||
| 142 | + const prettyPrint = (title, text, color) => { | ||
| 143 | + if (isProduction) return; | ||
| 144 | + if (typeof text === 'object') { | ||
| 145 | + console.log( | ||
| 146 | + `%c ${title} %c`, | ||
| 147 | + `background:${color};border:1px solid ${color}; padding: 1px; border-radius: 2px 0 0 2px; color: #fff;`,'background:transparent', | ||
| 148 | + text | ||
| 149 | + ) | ||
| 150 | + return | ||
| 151 | + } | ||
| 152 | + console.log( | ||
| 153 | + `%c ${title} %c ${text} %c`, | ||
| 154 | + `background:${color};border:1px solid ${color}; padding: 1px; border-radius: 2px 0 0 2px; color: #fff;`, | ||
| 155 | + `border:1px solid ${color}; padding: 1px; border-radius: 0 2px 2px 0; color: ${color};`, | ||
| 156 | + 'background:transparent' | ||
| 157 | + ); | ||
| 158 | + }; | ||
| 159 | + const info = (textOrTitle, content = '') => { | ||
| 160 | + const title = isEmpty(content) ? 'Info' : textOrTitle; | ||
| 161 | + const text = isEmpty(content) ? textOrTitle : content; | ||
| 162 | + prettyPrint(title, text, '#909399'); | ||
| 163 | + }; | ||
| 164 | + const error = (textOrTitle, content = '') => { | ||
| 165 | + const title = isEmpty(content) ? 'Error' : textOrTitle; | ||
| 166 | + const text = isEmpty(content) ? textOrTitle : content; | ||
| 167 | + prettyPrint(title, text, '#F56C6C'); | ||
| 168 | + }; | ||
| 169 | + const warning = (textOrTitle, content = '') => { | ||
| 170 | + const title = isEmpty(content) ? 'Warning' : textOrTitle; | ||
| 171 | + const text = isEmpty(content) ? textOrTitle : content; | ||
| 172 | + prettyPrint(title, text, '#E6A23C'); | ||
| 173 | + }; | ||
| 174 | + const success = (textOrTitle, content = '') => { | ||
| 175 | + const title = isEmpty(content) ? 'Success ' : textOrTitle; | ||
| 176 | + const text = isEmpty(content) ? textOrTitle : content; | ||
| 177 | + prettyPrint(title, text, '#67C23A'); | ||
| 178 | + }; | ||
| 179 | + | ||
| 180 | + return { | ||
| 181 | + info, | ||
| 182 | + error, | ||
| 183 | + warning, | ||
| 184 | + success, | ||
| 185 | + }; | ||
| 186 | +}; | ||
| 187 | + | ||
| 188 | +const isInViewport = (el) => { // 判断元素是否在可视区域 | ||
| 189 | + const rect = el.getBoundingClientRect(); | ||
| 190 | + return ( | ||
| 191 | + rect.top >= 0 && | ||
| 192 | + rect.left >= 0 && | ||
| 193 | + rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | ||
| 194 | + rect.right <= (window.innerWidth || document.documentElement.clientWidth) | ||
| 195 | + ); | ||
| 196 | +}; | ||
| 197 | + | ||
| 128 | export { | 198 | export { |
| 129 | formatDate, | 199 | formatDate, |
| 130 | wxInfo, | 200 | wxInfo, |
| ... | @@ -134,4 +204,6 @@ export { | ... | @@ -134,4 +204,6 @@ export { |
| 134 | changeURLArg, | 204 | changeURLArg, |
| 135 | getUrlParams, | 205 | getUrlParams, |
| 136 | stringifyQuery, | 206 | stringifyQuery, |
| 207 | + prettyLog, | ||
| 208 | + isInViewport, | ||
| 137 | }; | 209 | }; | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2024-07-12 13:20:15 | 2 | * @Date: 2024-07-12 13:20:15 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-08-01 11:51:07 | 4 | + * @LastEditTime: 2024-09-05 17:31:02 |
| 5 | * @FilePath: /data-table/src/views/test.vue | 5 | * @FilePath: /data-table/src/views/test.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| ... | @@ -10,11 +10,17 @@ | ... | @@ -10,11 +10,17 @@ |
| 10 | <TEditor ref="refEdit" ></TEditor> | 10 | <TEditor ref="refEdit" ></TEditor> |
| 11 | <div @click="getValue">获取内容</div> | 11 | <div @click="getValue">获取内容</div> |
| 12 | <div @click="setValue">设置内容</div> | 12 | <div @click="setValue">设置内容</div> |
| 13 | + <div> | ||
| 14 | + <ul id="list"> | ||
| 15 | + <li v-for="(item) in 50" :key="index">Item {{ item }}</li> | ||
| 16 | + </ul> | ||
| 17 | + </div> | ||
| 13 | </div> | 18 | </div> |
| 14 | </template> | 19 | </template> |
| 15 | 20 | ||
| 16 | <script setup> | 21 | <script setup> |
| 17 | import TEditor from "@/components/TEditor/index.vue"; | 22 | import TEditor from "@/components/TEditor/index.vue"; |
| 23 | + import { $ } from "@/utils/generatePackage.js"; | ||
| 18 | 24 | ||
| 19 | const refEdit = ref(null); | 25 | const refEdit = ref(null); |
| 20 | 26 | ||
| ... | @@ -55,10 +61,63 @@ | ... | @@ -55,10 +61,63 @@ |
| 55 | </tbody> | 61 | </tbody> |
| 56 | </table> | 62 | </table> |
| 57 | ` | 63 | ` |
| 64 | + | ||
| 65 | + onMounted(() => { | ||
| 66 | + $(document).ready(function() { | ||
| 67 | + const $listItems = $("#list li"); | ||
| 68 | + | ||
| 69 | + // 判断元素是否在可视范围内 | ||
| 70 | + function isInViewport($el) { | ||
| 71 | + const rect = $el[0].getBoundingClientRect(); | ||
| 72 | + const listRect = $('#list')[0].getBoundingClientRect(); // 获取容器的可视区域 | ||
| 73 | + return ( | ||
| 74 | + rect.top >= listRect.top && | ||
| 75 | + rect.bottom <= listRect.bottom | ||
| 76 | + ); | ||
| 77 | + } | ||
| 78 | + | ||
| 79 | + // 检查所有的 li 元素 | ||
| 80 | + function addVisibilityClass() { | ||
| 81 | + $listItems.each(function() { | ||
| 82 | + const $this = $(this); | ||
| 83 | + if (isInViewport($this) && !$this.hasClass("visible")) { | ||
| 84 | + $this.addClass("visible"); | ||
| 85 | + } | ||
| 86 | + }); | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + // 监听滚动事件 | ||
| 90 | + $("#list").on("scroll", function() { | ||
| 91 | + addVisibilityClass(); | ||
| 92 | + }); | ||
| 93 | + | ||
| 94 | + // 初次加载时检查可见项 | ||
| 95 | + addVisibilityClass(); | ||
| 96 | + }); | ||
| 97 | + }) | ||
| 58 | </script> | 98 | </script> |
| 59 | 99 | ||
| 60 | <style> | 100 | <style> |
| 61 | .tinymce-box { | 101 | .tinymce-box { |
| 62 | width: 100%; | 102 | width: 100%; |
| 63 | } | 103 | } |
| 104 | + | ||
| 105 | +ul { | ||
| 106 | + height: 200px; /* 可视区域显示5个li */ | ||
| 107 | + overflow-y: scroll; | ||
| 108 | + list-style-type: none; | ||
| 109 | + padding: 0; | ||
| 110 | + background-color: #eee; | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | +li { | ||
| 114 | + height: 40px; | ||
| 115 | + margin: 5px 0; | ||
| 116 | + opacity: 0; | ||
| 117 | + transition: opacity 0.5s ease; | ||
| 118 | +} | ||
| 119 | + | ||
| 120 | +li.visible { | ||
| 121 | + opacity: 1; | ||
| 122 | +} | ||
| 64 | </style> | 123 | </style> | ... | ... |
-
Please register or login to post a comment