在线获取iOS设备名称适配数据
经过这里一番折腾之后还是在线工具来的方便~
<!-- run -->
<style>
.device-data-bg {
width: 80%;
display: flex;
flex-direction: column;
justify-content: flex-start;
}
.copy-btn {
width: 100%;
height: 30px;
}
</style>
<div id="app">
<div class="device-data-bg">
<button class="copy-btn" @click="getIOSDevicesData">一键复制数据</button>
<textarea rows="15" cols="50">{{ JSON.stringify(iosDevs,null,4) }}</textarea>
</div>
</div>
<script>
// 复制到剪切板
function copy(text) {
let textareaEl = document.createElement('textarea');
// 防止手机上弹出软键盘
textareaEl.setAttribute('readonly', 'readonly');
textareaEl.value = text;
document.body.appendChild(textareaEl);
textareaEl.select();
let res = document.execCommand('copy');
document.body.removeChild(textareaEl);
window.ele.$notify({
title: '温馨提示',
message: '复制成功',
type: 'success',
position: 'top-right'
});
return res;
}
new Vue({
el: '#app',
data() {
return {
devices: [],
iosDevs: [],
}
},
mounted() {
this.getDevices();
},
methods: {
getIOSDevicesData() {
this.iosDevs = this.devices.filter(item => item.name.includes('iP')).map(item => {
return {
deviceName: item.name,
identifier: item.identifier
}
});
copy(JSON.stringify(this.iosDevs));
},
ajaxGetData(url, cb) {
let request = new XMLHttpRequest();
request.open('GET', url, true);
request.onreadystatechange = function () {
if (this.readyState === 4 && this.status === 200) {
cb(this.responseText);
}
}
request.send();
},
getDevices() {
let that = this;
this.ajaxGetData('https://api.ipsw.me/v4/devices', function (data) {
that.$nextTick(() => {
that.devices = JSON.parse(data);
that.getIOSDevicesData();
});
})
}
}
})
</script>
未经作者授权,禁止转载
本文来自博客园,作者:CoderWGB,转载请注明原文链接:https://www.cnblogs.com/wgb1234/articles/17555311.html
THE END