wlzboy
2025-09-23 f7ddeac884b4bdc5c608e5f34cf8f3c9d7c5e588
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
<template>
  <div class="anonymous-container">
    <div class="test-card">
      <h2 class="card-title">匿名访问测试</h2>
      <div class="form-content">
        <div class="form-item">
          <label>应用ID:</label>
          <input v-model="form.appId" placeholder="请输入应用ID" class="input-field" />
        </div>
        <div class="form-actions">
          <button class="btn btn-primary" @click="handleTest">测试访问</button>
          <button class="btn btn-success" @click="handleGenerateSign">生成签名</button>
        </div>
      </div>
 
      <!-- 显示签名信息 -->
      <div v-if="signInfo" class="info-card">
        <h3>签名信息</h3>
        <div class="info-item">
          <span class="label">时间戳:</span>
          <span class="value">{{ signInfo.timestamp }}</span>
        </div>
        <div class="info-item">
          <span class="label">签名:</span>
          <span class="value">{{ signInfo.sign }}</span>
        </div>
        <div class="info-item">
          <span class="label">签名字符串:</span>
          <span class="value">{{ signInfo.signStr }}</span>
        </div>
      </div>
 
      <!-- 显示测试结果 -->
      <div v-if="testResult" class="info-card">
        <h3>测试结果</h3>
        <pre class="result-content">{{ JSON.stringify(testResult, null, 2) }}</pre>
      </div>
    </div>
  </div>
</template>
 
<script>
import { generateSign, anonymousTest } from '@/api/anonymous'
import { Message } from 'element-ui'
 
export default {
  name: 'AnonymousTest',
  data() {
    return {
      form: {
        appId: ''
      },
      signInfo: null,
      testResult: null
    }
  },
  methods: {
    // 生成签名
    handleGenerateSign() {
      if (!this.form.appId) {
        Message.warning('请输入应用ID')
        return
      }
      generateSign(this.form.appId).then(response => {
        this.signInfo = response.data
        Message.success('签名生成成功')
      })
    },
    // 测试匿名访问
    handleTest() {
      if (!this.signInfo) {
        Message.warning('请先生成签名')
        return
      }
      const params = {
        appId: this.form.appId,
        sign: this.signInfo.sign,
        timestamp: this.signInfo.timestamp
      }
      anonymousTest(params).then(response => {
        this.testResult = response
        Message.success('测试成功')
      })
    }
  }
}
</script>
 
<style scoped>
.anonymous-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #f0f2f5;
  padding: 20px;
}
 
.test-card {
  background: white;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0,0,0,0.1);
  padding: 30px;
  width: 100%;
  max-width: 600px;
}
 
.card-title {
  margin: 0 0 20px;
  color: #333;
  text-align: center;
}
 
.form-content {
  margin-bottom: 20px;
}
 
.form-item {
  margin-bottom: 15px;
}
 
.form-item label {
  display: block;
  margin-bottom: 5px;
  color: #606266;
}
 
.input-field {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  font-size: 14px;
  transition: border-color 0.2s;
}
 
.input-field:focus {
  outline: none;
  border-color: #409eff;
}
 
.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}
 
.btn {
  padding: 8px 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  transition: opacity 0.2s;
}
 
.btn:hover {
  opacity: 0.8;
}
 
.btn-primary {
  background-color: #409eff;
  color: white;
}
 
.btn-success {
  background-color: #67c23a;
  color: white;
}
 
.info-card {
  margin-top: 20px;
  padding: 15px;
  background: #f8f9fa;
  border-radius: 4px;
}
 
.info-card h3 {
  margin: 0 0 15px;
  color: #333;
  font-size: 16px;
}
 
.info-item {
  margin: 10px 0;
  line-height: 1.5;
}
 
.label {
  font-weight: bold;
  color: #606266;
  margin-right: 10px;
}
 
.value {
  font-family: monospace;
  color: #666;
  word-break: break-all;
}
 
.result-content {
  background-color: #f5f7fa;
  padding: 15px;
  border-radius: 4px;
  margin: 10px 0 0;
  overflow-x: auto;
  font-family: monospace;
  font-size: 13px;
  line-height: 1.5;
}
</style>