InstallServer.vue 5.27 KB
Newer Older
牛文敏's avatar
init    
牛文敏 committed
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
<template>
  <div style="display: flex; flex-direction: column; align-items: center; height: 80vh;">
    <div style="display: flex; margin-bottom: 20px; flex-direction: column;">
      <h2>设备信息</h2>
      <table border="1" cellspacing="0" width="500" height="50">
        <tr>
          <td width="100">芯片型号:</td>
          <td>{{ data.chipInfo }}</td>
        </tr>
      </table>
    </div>
    <h2>线刷包</h2>
    <div style="display: flex; flex-direction: row; height: 30px;">
      <p style="margin: 0px;">如果是rockchip线刷包,请直接点击重启:</p>
      <button @click="reboot">重启</button>
    </div>
    <div style="display: flex; margin-bottom: 20px; flex-direction: column;">
      <h2>请选择刷机参数</h2>
      <table cellpadding="5px">
        <tbody>
          <tr v-for="(value) in packageInfoArray.model_database" :key="value.boxid">
            <td style="text-align: left;">
              <input type="radio" :value="value.boxid" name="boxid" :checked="index === 0"/>
            </td>
            <td style="text-align: left;">
              <label>boxid: {{ value.boxid }}</label>
            </td>
            <td style="text-align: left;">
              <label>soc: {{ value.soc }}</label>
            </td>
            <td style="text-align: left;">
              <label>model: {{ value.model }}</label>
            </td>
            <td style="text-align: left;">
              <label>dtb: {{ value.dtb }}</label>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <button style="align-items: end; margin-bottom: 20px;" @click="submitForm">提交</button>
    <textarea id="texts" style="width: 800px; height: 100%; margin-bottom: 20px; padding: 20px;" disabled v-model="outputTextarea">
    </textarea>
    <div style="display: flex; flex-direction: row; height: 30px;">
      <p style="margin: 0px;">提交数据后是否成功,如果不成功请关机设备后重启重新选择刷机参数:</p>
      <button @click="powerOff">关机</button>
    </div>
  </div>
</template>

<script setup>
import { useStore } from '@/stores'
import { ref,onMounted  } from 'vue'

const data = ref({})
const packageInfoArray = ref({})
const store = useStore()

const deviceData = () => {
  store.get('getInfo')
    .then((res) => {
      if(parseInt(JSON.parse(res.packageInfo).code, 10) !== 0){
        console.log(parseInt(JSON.parse(res.packageInfo).code, 10))
        alert("获取设备信息失败!")
      }
      data.value = res
      packageInfoArray.value = JSON.parse(data.value.packageInfo)
    })
    .catch((error) => {
      console.error(error);
    });
};

onMounted(deviceData)
const warning = '请根据您的设备型号,以及芯片型号选择正确的boxid进行刷机,若不知,可以重复尝试,注意:您在提交一组数据之后需要等待结果返回并进行关机重启之后。才可以选其他参数进行提交!!!'
const outputTextarea = ref(warning);

const submitForm = () => {
  const radioButtons = document.getElementsByName("boxid");
  let isChecked = false;
  outputTextarea.value = '写入emmc信息输出:写入中,请耐心等待....';
  for (let i = 0; i < radioButtons.length; i++) {
    if (radioButtons[i].checked) {
      store.post('armbianInstall', {
          body: JSON.stringify({
            'boxid': radioButtons[i].value,
          })
        }).then((res) => {
          if(res.code === 401){
            outputTextarea.value = warning;
            alert("请求参数错误");
          }else if(res.code === 102){
            outputTextarea.value = '安装信息输出:安装中,请耐心等待....';
            alert("正在处理中")
          }else if(res.code === 403){
            outputTextarea.value = "安装信息输出:"+warning;
            alert("禁止访问,请关机重启后再进行");
          }else if(res.code === 200){
            outputTextarea.value = res.result
            alert("安装成功!请点击关机后重启设备!")
          }else{
            outputTextarea.value = "写入emmc失败!!请选择正确的参数进行提交\n"
            alert("写入emmc出错,请检查参数是否选择正确,可点击关机后重启设备重新选择!")
          }
        })
    .catch((error) => {
      console.error(error);
    });
      isChecked = true;
      break;
    }
  }
  if (!isChecked) {
    outputTextarea.value = warning;
    alert("请选择一个参数后提交!");
    return;
  }
};
  
const reboot = () => {             
        store.post('initDev').then((res) => {
          if(res.code === 401){
            alert("请求参数错误")
          }else if(res.code === 102){
            alert("正在处理中")
          }else if(res.code === 403){
            alert("禁止访问,请关机重启后再进行")
          }
        })
    .catch((error) => {
      console.error(error);
    });             
}

const powerOff = () => {
        store.post('powerOff').then((res) => {
          if(res.code === 401){
            alert("请求参数错误")
          }else if(res.code === 102){
            alert("正在处理中")
          }else if(res.code === 403){
            alert("禁止访问,请关机重启后再进行")
          }
        })
    .catch((error) => {
      console.error(error);
    });
}

</script>

<style>

</style>