新大宝股票管理后台
1
jhzh
2025-07-09 5345d78885467ad07c42cfc3a57fc60059854703
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
<template>
  <div class="account-settings-info-view">
    <a-form layout="vertical" :form="addUserform" ref="addUserform" v-if="!googleAuthBind">
      <a-row :gutter="16" type="flex" justify="center">
        <a-col :order="isMobile ? 2 : 1" :md="24" :lg="16">
          <a-form-item label="秘钥">
            <a-input
              placeholder="请点击右侧 生成秘钥和二维码"
              readonly    
              @click="handleCopy"
              :addonAfter="addonContent"
              v-decorator="['secret', { rules: [{ required: false, message: '请输入您的昵称' }] }]"
            />
            <img v-if="googleAuthimg" style="width: 100px;margin-top:10px;" :src="googleAuthimg"/>
          </a-form-item>
          
          <a-form-item label="谷歌验证码">
            <a-input
              placeholder="请输入谷歌验证码"
              v-decorator="['googleAuthCode', { rules: [{ required: true, message: '请输入谷歌验证码' }] }]"
            />
          </a-form-item>
 
          <!-- <a-form-item label="超级谷歌验证码">
            <a-input
              placeholder="请输入超级谷歌验证码"
              v-decorator="['rootGoogleAuthCode', { rules: [{ required: true, message: '请输入超级谷歌验证码' }] }]"
            />
          </a-form-item> -->
          <a-form-item>
            <a-button type="primary" @click="saveinfo">绑定</a-button>
          </a-form-item>
        </a-col>
      </a-row>
    </a-form>
    <div v-else style="">
      <div style="margin-bottom: 20px;">已绑定</div>
      
      <a-form-item label="谷歌验证码">
        <a-input
          placeholder="请输入谷歌验证码"
          v-model="ggyzm"
          v-decorator="['googleAuthCode', { rules: [{ required: true, message: '请输入谷歌验证码' }] }]"
        />
      </a-form-item>
      
      <a-button type="primary" @click="adskille">解绑</a-button>
    </div>
    <avatar-modal ref="modal" @ok="setavatar" />
  </div>
</template>
 
<script>
import AvatarModal from './AvatarModal'
import { baseMixin } from '@/store/app-mixin'
import { adminlist, adminupdate,bindGoogleAuth,getLoginGoogleAuthSecret,getAdmin,unbindingGoogleAuth } from '@/api/managesettings'
import pick from 'lodash.pick'
export default {
  mixins: [baseMixin],
  components: {
    AvatarModal,
  },
  data() {
    return {
      // cropper
      addonContent: (
              <a
                onClick={this.handleGenerate} // 这里是点击事件
              >
                生成秘钥和二维码
              </a>
      ),
      preview: {},
      googleAuthimg:'',
      ggyzm:'',
      userid:'',
      googleAuthBind:'',
      option: {
        img: '/avatar2.jpg',
        info: true,
        size: 1,
        outputType: 'jpeg',
        canScale: false,
        autoCrop: true,
        // 只有自动截图开启 宽度高度才生效
        autoCropWidth: 180,
        autoCropHeight: 180,
        fixedBox: true,
        // 开启宽度和高度比例
        fixed: true,
        fixedNumber: [1, 1],
      },
      settingdetail: {},
      addUserform: this.$form.createForm(this),
      fields: ['googleAuthCode', 'secret','id'],
    }
  },
  mounted() {
    this.getnowuser()
  },
  methods: {
    adskille(){
          var values ={}
          values.rootGoogleAuthCode = this.ggyzm
          values.id = this.userid
          unbindingGoogleAuth(values).then((res) => {
            if (res.status == 0) {
              this.getnowuser()
              this.$message.success({ content: '解绑成功', duration: 2 });
              form.resetFields();
            } else {
              this.$message.error(res.msg);
            }
          });
    },
    getnowuser() {
      getAdmin().then((res) => {
        if(res.status==0){
          this.userid = res.data.id
          this.googleAuthBind = res.data.googleAuthBind
        }
        console.log(res);
      })
    },
    setavatar(url) {
      this.option.img = url
    },
    handleCopy() {
          // 使用浏览器的 execCommand 来实现复制功能
          const input = document.createElement('input');
          input.value = this.addUserform.getFieldValue('secret');  // 这里用你的秘钥变量
          document.body.appendChild(input);
          input.select();
          document.execCommand('copy');
          document.body.removeChild(input);
    
          this.$message.success('秘钥已复制');
     },
    handleGenerate() {
      getLoginGoogleAuthSecret().then((res) => {
        if (res.status == 0) {
          // this.$set(this.$refs.addUserform.form, 'secret', res.data.googleAuthSecret);
          this.addUserform.setFieldsValue({
            secret: res.data.googleAuthSecret,
          })
          this.googleAuthimg = res.data.googleAuthImg;
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    saveinfo() {
      const form = this.$refs.addUserform.form;
      form.validateFields((errors, values) => {
        if (!errors) {
          values.id = this.userid
          bindGoogleAuth(values).then((res) => {
            if (res.status == 0) {
              this.getnowuser()
              this.$message.success({ content: '绑定成功', duration: 2 });
              form.resetFields();
              this.getnowuser();
            } else {
              this.$message.error(res.msg);
            }
          });
        }
      });
    }
  },
}
</script>
 
<style lang="less" scoped>
.avatar-upload-wrapper {
  height: 200px;
  width: 100%;
}
 
.ant-upload-preview {
  position: relative;
  margin: 0 auto;
  width: 100%;
  max-width: 180px;
  border-radius: 50%;
  box-shadow: 0 0 4px #ccc;
 
  .upload-icon {
    position: absolute;
    top: 0;
    right: 10px;
    font-size: 1.4rem;
    padding: 0.5rem;
    background: rgba(222, 221, 221, 0.7);
    border-radius: 50%;
    border: 1px solid rgba(0, 0, 0, 0.2);
  }
 
  .mask {
    opacity: 0;
    position: absolute;
    background: rgba(0, 0, 0, 0.4);
    cursor: pointer;
    transition: opacity 0.4s;
 
    &:hover {
      opacity: 1;
    }
 
    i {
      font-size: 2rem;
      position: absolute;
      top: 50%;
      left: 50%;
      margin-left: -1rem;
      margin-top: -1rem;
      color: #d6d6d6;
    }
  }
 
  img,
  .mask {
    width: 100%;
    max-width: 180px;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
  }
}
</style>
 
<style>
</style>