lin
2026-05-09 961cc2838a832878ed8f506f64a33ce43590be6f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
<script>
export default {
  name: "ProtocolPopup",
 
  props:{
    code:{ type:String, default:'' },
    title:{ type:String, default:'' },
    getPlatformProtocolNewList:{
      type:Array,
      default:() => []
    }
  },
 
  data(){
    return {
      list: [],
      text:'',
      titleText:'',
      flag:false,
      ing:0,
      scrollTop: 0,
 
      reachBottom:false,
      readingTimer:null,
      readTime:500,
 
      tiems:5,
      timer:null, // 倒计时
    }
  },
 
  created() {
    const _this = this;
 
    // 多协议
    if(this.getPlatformProtocolNewList.length){
 
      const cache = uni.getStorageSync('protocol_read_cache') || {};
 
      this.list = this.getPlatformProtocolNewList.map((item, index) => ({
        ...item,
        // isRead: cache[index]?.isRead || false
        isRead:  false
      }));
 
      this.ing = cache.ing || 0;
 
      this.updateCurrent();
      this.checkAllRead();
      return;
    }
 
    // 单协议
    uni.request({
      url: this.$webHost + `/api/v2/protocolInfo/getProtocol?appId=xxx&code=${this.code}`,
      success: (res) => {
        _this.text = res.data.data.content;
        _this.titleText = res.data.data.name;
        _this.flag = false;
      }
    })
  },
 
  methods:{
    open(){
      this.$refs.boxCnt.open();
      this.startCountDown();
    },
 
    closePopup() {
      this.$refs.boxCnt.close()
    },
 
    // ✅ 倒计时
    startCountDown(){
      this.tiems = 5;
 
      if(this.timer){
        clearInterval(this.timer);
      }
 
      this.timer = setInterval(() => {
        if(this.tiems > 0){
          this.tiems--;
        }else{
          clearInterval(this.timer);
          this.timer = null;
        }
      },1000);
    },
 
    // 更新当前协议
    updateCurrent(){
      this.text = this.list[this.ing].content;
      this.titleText = this.list[this.ing].name;
      this.scrollTop = 0;
 
      this.reachBottom = false;
 
      if(this.readingTimer){
        clearTimeout(this.readingTimer);
      }
 
      // 每个协议重新倒计时
      this.startCountDown();
    },
 
    // 滚动到底
    scrolltolower(){
      if(!this.list.length){
        this.flag = true;
        return;
      }
 
      if(this.reachBottom) return;
 
      this.reachBottom = true;
 
      if(this.readingTimer){
        clearTimeout(this.readingTimer);
      }
 
      this.readingTimer = setTimeout(() => {
 
        this.list[this.ing].isRead = true;
 
        this.saveCache();
 
        const allRead = this.list.every(item => item.isRead);
 
        if (allRead) {
          this.flag = true;
        } else {
 
        }
 
      }, this.readTime);
    },
 
    // scroll 兜底
    onScroll(e){
      const { scrollTop, scrollHeight, deltaY } = e.detail;
 
      if(scrollTop + deltaY >= scrollHeight - 100){
        this.scrolltolower();
      }
    },
 
    // 缓存
    saveCache(){
      const cache = {
        ing: this.ing,
        ...this.list.reduce((acc, item, index) => {
          acc[index] = { isRead: item.isRead };
          return acc;
        }, {})
      };
 
      uni.setStorageSync('protocol_read_cache', cache);
    },
 
    // 判断是否全部读完
    checkAllRead(){
      this.flag = this.list.every(item => item.isRead);
    },
 
    // 点击确认
    loadPopup(){
      console.log(this.flag);
      if(!this.flag){
        if(this.getPlatformProtocolNewList.length && this.reachBottom){
          if(this.readingTimer){
            clearTimeout(this.readingTimer);
          }
          this.scrollTop = 0;
 
          this.ing++;
          if(this.ing === this.getPlatformProtocolNewList.length){
            this.flag = true;
 
            uni.removeStorageSync('protocol_read_cache');
 
            this.$refs.boxCnt.close();
            this.$emit('confirm');
            return;
          }
          this.updateCurrent();
        } else {
          uni.showToast({
            title: '请先阅读完本协议内容',
            icon: 'none',
          })
        }
 
        return;
      }
      if(!this.flag || this.tiems > 0) return;
 
      uni.removeStorageSync('protocol_read_cache');
 
      this.$refs.boxCnt.close();
      this.$emit('confirm');
    }
  },
 
  beforeDestroy(){
    if(this.timer){
      clearInterval(this.timer);
    }
    if(this.readingTimer){
      clearTimeout(this.readingTimer);
    }
  }
}
</script>
 
<template>
  <uv-popup
      ref="boxCnt"
      z-index="999"
      :round="16"
      :safe-area-inset-bottom="true"
      :closeOnClickOverlay="false"
  >
    <view class="box">
 
      <!-- 标题 -->
      <view class="title">
        {{ titleText }}
      </view>
 
      <!-- 进度 -->
      <view v-if="list.length" class="progress">
        {{ ing + 1 }} / {{ list.length }}
      </view>
      <view v-if="!reachBottom" class="scroll-tip">
        ↓ 请滑动阅读全部内容
      </view>
      <!-- 内容 -->
      <scroll-view
          :key="ing"
          scroll-y
          :scroll-top="scrollTop"
          @scroll="onScroll"
          @scrolltolower="scrolltolower"
          lower-threshold="50"
          style="height: 70vh;"
          :show-scrollbar="true"
      >
        <view class="text-container">
          <rich-text :nodes="text"></rich-text>
        </view>
      </scroll-view>
 
      <!-- 按钮 -->
      <view style="margin-top: 20rpx;">
        <uv-button
 
            :disabled="!flag || tiems > 0"
            @click="loadPopup"
            v-if="code"
            :custom-style="{ color: (!flag || tiems > 0 )? '#666' : '#FF1472',border:'none' }"
        >
          确定
          <text v-show="tiems">({{ tiems }}S)</text>
        </uv-button>
        <uv-button
            :disabled="tiems > 0 || !reachBottom"
            @click="loadPopup"
            v-if="getPlatformProtocolNewList.length"
            :custom-style="{
        color: (tiems > 0 || !reachBottom) ? '#666' : '#FF1472',
        border: 'none'
    }"
        >
          {{ flag || getPlatformProtocolNewList.length === ing + 1 ? '确定' : '下一步' }}
          <text v-show="tiems">({{ tiems }}S)</text>
        </uv-button>
      </view>
 
    </view>
  </uv-popup>
</template>
 
<style scoped lang="scss">
.box{
  padding: 40rpx;
  width:80vw;
  margin: auto;
  border-radius: 40rpx;
  background: white;
}
 
.title{
  text-align: center;
  font-weight: 800;
  margin-bottom: 10rpx;
  font-size: 34rpx;
}
 
.progress{
  text-align: center;
  font-size: 24rpx;
  color: #999;
  margin-bottom: 10rpx;
}
 
.text-container {
  font-size: 28rpx;
  line-height: 1.8;
  color: #666;
}
.uni-scroll-view::-webkit-scrollbar {
  width: 6px;
}
 
.uni-scroll-view::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.3);
  border-radius: 10px;
}
 
.uni-scroll-view::-webkit-scrollbar-track {
  background: transparent;
}
.scroll-tip{
  text-align:center;
  color:#999;
  font-size:24rpx;
  margin:10rpx 0;
}
</style>