OSDN Git Service

43f116853aee92479d36ac538cdd3e8a2ed9ea4b
[bytom/Byone.git] / src / views / backup / backup.vue
1 <style lang="scss" scoped >
2   .item-block{
3     display: flex;
4     align-items: center;
5     font-weight: 600;
6     font-size: 15px;
7     letter-spacing: 0.2px;
8     i{
9       width: 24px;
10       height: 24px;
11       background: #F5F5F5;
12       font-weight: normal;
13       border-radius: 24px;
14       text-align: center;
15       padding: 10px;
16     }
17   }
18
19   .disable{
20     cursor: not-allowed;
21     color: grey;
22     pointer-events: none;
23
24     &:hover{
25       border:none;
26       padding:14px;
27     }
28   }
29
30
31 </style>
32
33 <template>
34   <div class="warp-menu bg-grey">
35     <div class="list menu-list">
36       <div :class="['list-item', {disable: !vault}]" @click="$refs.modalPasswd.open()" >
37         <div class="item-block">
38           <i class="iconfont iconbackup_line"></i>{{ $t('backup.mnemonic') }}
39         </div>
40       </div>
41       <div class="list-item" @click="backupKeystore">
42         <div class="item-block">
43           <i class="iconfont iconbackup_line"></i>{{ $t('backup.keystore') }}
44         </div>
45       </div>
46     </div>
47
48     <modal-passwd ref="modalPasswd" @confirm="openMnemonicView"></modal-passwd>
49     <!-- child menu -->
50     <router-view></router-view>
51   </div>
52 </template>
53
54
55 <script>
56 import account from "@/models/account";
57 import FileSaver from "file-saver";
58 import { mapActions, mapGetters, mapState } from 'vuex'
59 import * as Actions from '@/store/constants';
60 import {RouteNames} from '@/router'
61
62 export default {
63     name: "",
64     data() {
65         return {};
66     },
67     computed: {
68       vault(){
69         if(this.currentAccount){
70           return this.currentAccount.vault;
71         }
72         return undefined;
73       },
74       ...mapState([
75         'bytom'
76       ]),
77       ...mapGetters([
78         'currentAccount'
79       ])
80     },
81     methods: {
82         openMnemonicView(password){
83           try{
84             const mnemonic = account.decryptMnemonic(this.vault, password, this)
85             this[Actions.SET_MNEMONIC](mnemonic).then(()=>{
86               this.$router.push({ name: RouteNames.BACKUP_MNEMONIC })
87             })
88           }
89           catch (e){
90             this.$toast.error(
91               e.message || e
92             );
93           }
94
95         },
96         backupKeystore() {
97           const keystore = JSON.stringify(this.currentAccount.keystore)
98           var blob = new Blob([keystore], {
99               type: "text/plain;charset=utf-8"
100           });
101           FileSaver.saveAs(blob, `byone_backup_${+new Date()}.dat`);
102         },
103       ...mapActions([
104         Actions.SET_MNEMONIC
105       ])
106     }
107 };
108 </script>