安全教育平台微信小程序(hbuilder打开后运行到微信开发者程序)
祖安之光
2025-08-07 5785bf8269c89f5098c60c18980ccb081b4adfe6
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
<template>
    <view class="box">
        <!-- 页面内容 -->
    <view class="m-p-15">
      <view class="cardList" v-if="quizList && quizList.length>0">
        <scroll-view scroll-y="true" class="scroll-Y" @scrolltoupper="upper"
                     @scrolltolower="lower" lower-threshold="150" @scroll="scrollView" style="height:100%">
          <view style="padding: 20px 0 20px">
          <view class="card-i" v-for="(item,index) in quizList" :key="index">
              <view class="card-i-l">
              <view>{{item.name}}</view>
                <span style="display:block;color: #999;font-size: 12px;margin-bottom: 10px;">已刷{{item.exerciseCount}}/{{item.totalCount}}</span>
                <span style="display:flex;align-items: center;color: #999;font-size: 12px;"><u-icon name="clock" color="#999" size="18" style="margin-bottom: 0;margin-right: 2px"></u-icon>{{item.createTime}}</span>
              </view>
              <view class="card-i-r">
                      <u-button v-if="item.exerciseCount == 0" class="study-button" type="success" text="开始刷题" shape="circle" size="small" @click="getQuestionIds(item,1)"></u-button>
                <u-button v-if="item.exerciseCount > 0" class="study-button" type="success" text="继续刷题" shape="circle" size="small" @click="getQuestionIds(item,2)"></u-button>
                <u-button class="study-button" type="error" text="查看错题" shape="circle" size="small" @click="getQuestionIds(item,3)"></u-button>
                <u-button class="study-button" text="重置" shape="circle" size="small" @click="reSet(item.id)"></u-button>
              </view>
          </view>
          </view>
        </scroll-view>
      </view>
      <u-empty v-else text="暂无记录" mode="data"></u-empty>
    </view>
    </view>
</template>
 
<script>
  import {getQuizHouse,getCleanRecord} from '../../../api/wearhouse.js'
  import VUE_APP_BASE_URL from "../../../common/constant";
    export default {
        components:{
        },
        data() {
            return {
                page: 'pages/tabBar/wearhouse/wearhouse',
                statusBarHeight: 0,
        classParams: {
          pageNum: 1,
          pageSize: 10,
        },
        quizList: [],
        totalPage: 0,
            }
        },
        onLoad() {
            // this.unitType = uni.getStorageSync('unittype') + 1;
            //获取手机状态栏高度
            this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'];
      this.classParams.pageNum = 1
      this.getQuizList()
        },
        onShow() {
            // this.role = uni.getStorageSync('roleName');
        },
    created(){
      // uni.hideTabBar()
    },
    mounted(){
 
    },
        methods: {
            loginOut() {
                uni.clearStorageSync();
                uni.clearStorage();
                uni.navigateTo({
                    url: '/pages/index/index'
                })
            },
            goBack() {
                uni.switchTab({
                    url:'/pages/tabBar/firstPage/firstPage'
                });
            },
 
      getQuizList(){
        const t = this
        getQuizHouse(t.classParams).then(res => {
          if(res.code == 200) {
            let list = res.data.list?res.data.list: [];
            if (res.data.pageNum != 1) {
              t.quizList = t.quizList.concat(list)
            } else {
              t.quizList = list
            }
            t.totalPage = res.data.totalPage
          }else{
            uni.$u.toast(res.message)
          }
        })
      },
 
      async getQuestionIds(item,type){
        if(item.totalCount == 0){
          uni.showToast({
            title: '该题库暂无题目',
            duration: 1000
          });
          return
        }
        // if(type == 2 && item.totalCount == item.exerciseCount){
        //   uni.showToast({
        //     title: '该题库所有题目已刷完',
        //     duration: 1000
        //   });
        //   return
        // }
        uni.setStorageSync("prevPage", '/pages/tabBar/wearhouse/wearhouse');
        uni.navigateTo({
          url: `/pages/tabBar/wearhouse/questions?bank=` + encodeURIComponent(JSON.stringify(item)) + `&type=` + encodeURIComponent(JSON.stringify(type))
        })
      },
 
      reSet(id){
        const t = this
        uni.showModal({
          title: '提示',
          content: '是否重置所选题库的刷题记录?',
          success: async function (res) {
            if (res.confirm) {
              const res = await getCleanRecord({bankId: id})
              if(res.code == 200){
                uni.showToast({
                  title: '刷题记录已重置',
                  duration: 1000
                });
                // t.classParams.pageNum = 1
                // t.getQuizList()
                uni.reLaunch({
                  url: '/pages/tabBar/wearhouse/wearhouse'
                })
              }else{
                uni.showToast({
                  title: '记录重置失败,请稍后再试',
                  duration: 1000
                });
              }
            } else if (res.cancel) {
              console.log('用户点击取消');
            }
          }
        })
      },
      upper(e) {
        // console.log(e)
      },
      lower(e) {
        //并且让页码+1,调用获取数据的方法获取第二页数据
        this.classParams.pageNum++
        //此处调用自己获取数据列表的方法
        if (this.classParams.pageNum > this.totalPage){
          uni.$u.toast('已加载全部数据')
          return
        }
        this.getQuizList()
      },
      scrollView(e) {
        // console.log(e)
      }
        }
    }
 
</script>
 
<style lang="scss" scoped>
 
.m-p-15{
  width: 100%;
  
  ::v-deep .u-empty{
        margin-top: 300rpx !important;
  }
}
.cardList{
  width: 100%;
  height: 100vh;
  box-sizing: border-box;
 
  .card-i{
    width: calc(100% - 30px);
    background: #fff;
    border-radius: 20rpx;
    padding: 15px;
    margin: 0 auto 15px;
    position: relative;
    display: flex;
    align-items: flex-start;
    box-sizing: border-box;
    box-shadow: 4px 4px 12px rgba(150,150,150,.05);
 
    &:last-of-type{
      margin-bottom: 0;
    }
    
  .card-i-l{
    width: 75%;
    &>view{
      width: 100%;
      font-size: 36rpx;;
      font-family: "PingFang SC";
      font-weight: 800;
      margin-bottom: 10rpx;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
  }
  .card-i-r{
    width: 25%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    ::v-deep .u-button{
      width: 100%;
      margin-bottom: 10rpx !important;
      
      &:last-of-type{
          margin-bottom: 0 !important;
      }
    }
  }
  }
}
 
</style>