|
|
@@ -384,59 +384,43 @@
|
|
|
const checkTextOverflow = () => {
|
|
|
nextTick(() => {
|
|
|
const instance = getCurrentInstance();
|
|
|
- // 安全保护
|
|
|
- if (!instance || !instance.proxy) {
|
|
|
- // 备用方案:全局查询(要求元素 class 唯一)
|
|
|
- let taskDescAllHeight = 0,
|
|
|
- taskDescHeight = 0;
|
|
|
- const query = uni.createSelectorQuery();
|
|
|
- query.select('.task_desc_all').boundingClientRect((rect) => {
|
|
|
- taskDescAllHeight = rect?.height || 0;
|
|
|
- });
|
|
|
- query.select('.task_desc').boundingClientRect((rect) => {
|
|
|
- taskDescHeight = rect?.height || 0;
|
|
|
- });
|
|
|
- query.select('.page_content_data').boundingClientRect((rect) => {
|
|
|
- state.searchBoxTop = rect?.top || 0;
|
|
|
- });
|
|
|
- query.exec(() => {
|
|
|
- // 所有回调执行完毕后触发
|
|
|
- state.showExpandBtn = taskDescAllHeight > taskDescHeight + 1;
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- let taskDescAllHeight = 0,
|
|
|
- taskDescHeight = 0;
|
|
|
- const query = uni.createSelectorQuery().in(instance.proxy);
|
|
|
- query.select('.task_desc_all').boundingClientRect((rect) => {
|
|
|
- taskDescAllHeight = rect?.height || 0;
|
|
|
- });
|
|
|
- query.select('.task_desc').boundingClientRect((rect) => {
|
|
|
- taskDescHeight = rect?.height || 0;
|
|
|
- });
|
|
|
- query.select('.page_content_data').boundingClientRect((rect) => {
|
|
|
- state.searchBoxTop = rect?.top || 0;
|
|
|
- });
|
|
|
- query.exec(() => {
|
|
|
- // 所有回调执行完毕后触发
|
|
|
+ const query = instance && instance.proxy
|
|
|
+ ? uni.createSelectorQuery().in(instance.proxy)
|
|
|
+ : uni.createSelectorQuery();
|
|
|
+
|
|
|
+ query.select('.task_desc_all').boundingClientRect();
|
|
|
+ query.select('.task_desc').boundingClientRect();
|
|
|
+ query.select('.page_content_data').boundingClientRect();
|
|
|
+
|
|
|
+ query.exec((res) => {
|
|
|
+ const rectAll = res[0];
|
|
|
+ const rectShort = res[1];
|
|
|
+ const rectPageData = res[2];
|
|
|
+
|
|
|
+ const taskDescAllHeight = rectAll?.height || 0;
|
|
|
+ const taskDescHeight = rectShort?.height || 0;
|
|
|
+ state.searchBoxTop = rectPageData?.top || 0;
|
|
|
+
|
|
|
state.showExpandBtn = taskDescAllHeight > taskDescHeight + 1;
|
|
|
});
|
|
|
});
|
|
|
- }
|
|
|
+ };
|
|
|
// 展开收起切换
|
|
|
const toggleExpand = () => {
|
|
|
state.isExpand = !state.isExpand;
|
|
|
nextTick(() => {
|
|
|
const instance = getCurrentInstance();
|
|
|
- // 安全保护
|
|
|
- if (!instance || !instance.proxy) {
|
|
|
- // 备用方案:全局查询(要求元素 class 唯一)
|
|
|
- query.select('.page_content_data').boundingClientRect((rect) => {
|
|
|
- state.searchBoxTop = rect?.top || 0;
|
|
|
- });
|
|
|
- return;
|
|
|
- }
|
|
|
- query.select('.page_content_data').boundingClientRect((rect) => {
|
|
|
+ // 自动选择查询上下文,消除重复if‑else
|
|
|
+ const query = instance && instance.proxy
|
|
|
+ ? uni.createSelectorQuery().in(instance.proxy)
|
|
|
+ : uni.createSelectorQuery();
|
|
|
+
|
|
|
+ // 只注册查询,不在回调做赋值
|
|
|
+ query.select('.page_content_data').boundingClientRect();
|
|
|
+
|
|
|
+ // exec才真正执行查询,res[0]对应上面select的结果
|
|
|
+ query.exec((res) => {
|
|
|
+ const rect = res?.[0];
|
|
|
state.searchBoxTop = rect?.top || 0;
|
|
|
});
|
|
|
});
|