deviceInfo.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view class="container">
  3. <view class="qrcode-box">
  4. <view class="qrcode">
  5. <image class="qrcodeImg" v-show="hide" :src="image" mode="aspectFill" @longpress="savePoster"></image>
  6. <uqrcode ref="uqrcode" :hide="hide" canvas-id="qrcode" :value="qrValue" size="300" sizeUnit="rpx" @complete="onComplete"></uqrcode>
  7. </view>
  8. </view>
  9. <view class="qrcode-tips"><text v-show="success">绑定二维码(长按保存)</text></view>
  10. <view class="box-item" @click="setSIM()">
  11. <view class="box-iteml">手表SIM卡号</view>
  12. <view class="box-itemr">
  13. <text>去设置</text>
  14. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png" mode="aspectFill"></image>
  15. </view>
  16. </view>
  17. <view class="box-item">
  18. <view class="box-iteml">IMEI号</view>
  19. <view class="box-itemr" v-if="deviceInfo.deviceId">
  20. <view class="copybtn" @tap="copyIMEI">复制</view>
  21. <text>{{deviceInfo.deviceId}}</text>
  22. </view>
  23. </view>
  24. <view class="box-item">
  25. <view class="box-iteml">固件版本</view>
  26. <view class="box-itemr">
  27. <text>{{deviceInfo.version}}</text>
  28. <image class="arrow_black" src="@/static/images/pages_watch/icons/my_right_arrow_right_icon.png" mode="aspectFill"></image>
  29. </view>
  30. </view>
  31. <myDialog ref="inputDialog" title="输入SIM卡号" @cancel="onCancel" @confirm="onConfirm">
  32. <template v-slot:dialogBody>
  33. <view class="popbody">
  34. <view class="inputDialog-tips">请输入手表的通话号码</view>
  35. <view class="uni-input-wrapper">
  36. <view class="uni-input">
  37. <input placeholder="请输入号码" :value="value" maxlength="100" :focus='focusState'
  38. @input="onKeyInput" />
  39. </view>
  40. <uni-icons type="clear" size="20" color="#aaa" v-if="showClearIcon"
  41. @click="clearIcon"></uni-icons>
  42. </view>
  43. </view>
  44. </template>
  45. </myDialog>
  46. </view>
  47. </template>
  48. <script>
  49. import myDialog from "@/pages_watch/components/myDialog/myDialog.vue";
  50. import {getDeviceData,getDeviceDataJson,updateSim} from "@/api/pages_watch/index.js"
  51. export default {
  52. components: {
  53. myDialog
  54. },
  55. data() {
  56. return {
  57. deviceId: uni.getStorageSync("deviceId") || '',
  58. deviceInfo: {},
  59. value: "",
  60. showClearIcon: false,
  61. focusState: true,
  62. qrValue: "",
  63. hide: false,
  64. success: false,
  65. image: "",
  66. downImg: ""
  67. }
  68. },
  69. onLoad() {
  70. this.getDeviceData()
  71. },
  72. methods: {
  73. getDeviceData() {
  74. getDeviceData({deviceId: this.deviceId}).then(res=>{
  75. if(res.code == 200) {
  76. this.deviceInfo = res.data || {}
  77. this.value = this.deviceInfo.sim || ''
  78. this.qrValue = JSON.stringify(this.deviceInfo)
  79. }
  80. })
  81. },
  82. onComplete(e) {
  83. this.hide = true
  84. this.success = e.success
  85. if(this.success) {
  86. this.$refs.uqrcode.toTempFilePath({
  87. success: res => {
  88. this.image = res.tempFilePath
  89. }
  90. });
  91. }
  92. },
  93. copyIMEI(text) {
  94. uni.setClipboardData({
  95. data: this.deviceInfo.deviceId,
  96. success:()=>{
  97. uni.showToast({
  98. title:'内容已成功复制到剪切板',
  99. icon:'none'
  100. })
  101. }
  102. });
  103. },
  104. setSIM() {
  105. this.value = this.deviceInfo.sim
  106. this.$refs.inputDialog.open()
  107. this.$nextTick(() => {
  108. this.focusState = true
  109. })
  110. },
  111. onKeyInput(event) {
  112. this.value = event.detail.value;
  113. if (event.detail.value.length > 0) {
  114. this.showClearIcon = true;
  115. } else {
  116. this.showClearIcon = false;
  117. }
  118. },
  119. clearIcon() {
  120. this.value = '';
  121. this.showClearIcon = false;
  122. },
  123. onCancel() {
  124. this.$refs.inputDialog.close()
  125. },
  126. onConfirm() {
  127. if(!this.value) {
  128. uni.showToast({
  129. title: "请输入号码",
  130. icon: "none"
  131. })
  132. return
  133. }
  134. uni.showLoading()
  135. updateSim({deviceId: this.deviceId,sim:this.value}).then(res=>{
  136. uni.hideLoading()
  137. if(res.code == 200) {
  138. this.deviceInfo.sim = this.value
  139. this.$refs.inputDialog.close()
  140. }
  141. }).catch(()=>{
  142. uni.hideLoading()
  143. })
  144. },
  145. savePoster() {
  146. uni.showActionSheet({
  147. itemList: ['保存图片到本地'],
  148. success: (res)=> {
  149. this.uploadFile()
  150. }
  151. });
  152. },
  153. uploadFile() {
  154. uni.uploadFile({
  155. url: uni.getStorageSync('requestPath')+'/app/common/uploadOSS', //仅为示例,非真实的接口地址
  156. filePath: this.image,
  157. name: 'file',
  158. success: (uploadFileRes) => {
  159. const info = JSON.parse(uploadFileRes.data); // 返回的是字符串,需要转成对象格式
  160. this.downImg = info.url
  161. if(info.code == 200){
  162. uni.saveImageToPhotosAlbum({
  163. filePath: this.downImg,
  164. success: () => {
  165. uni.showToast({
  166. title: "保存成功",
  167. icon: "success",
  168. });
  169. },
  170. fail: () => {
  171. uni.showToast({
  172. title: "保存失败",
  173. icon: "error",
  174. });
  175. },
  176. });
  177. } else {
  178. uni.showToast({
  179. title: "保存失败",
  180. icon: "error",
  181. });
  182. }
  183. }
  184. });
  185. }
  186. }
  187. }
  188. </script>
  189. <style lang="scss" scoped>
  190. @mixin u-flex($flexD, $alignI, $justifyC) {
  191. display: flex;
  192. flex-direction: $flexD;
  193. align-items: $alignI;
  194. justify-content: $justifyC;
  195. }
  196. .popbody {
  197. display: flex;
  198. flex-direction: column;
  199. align-items: center;
  200. .inputDialog-tips {
  201. font-size: 28rpx;
  202. text-align: center;
  203. }
  204. .uni-input-wrapper {
  205. background-color: #f0f0f0;
  206. width: 450rpx;
  207. padding: 18rpx 20rpx;
  208. margin: 40rpx 0;
  209. box-sizing: border-box;
  210. display: flex;
  211. flex-direction: row;
  212. align-items: center;
  213. justify-content: space-around;
  214. .uni-input {
  215. flex: 1;
  216. }
  217. }
  218. }
  219. .container {
  220. width: 100%;
  221. background-color: #fff;
  222. padding: 0 24rpx;
  223. box-sizing: border-box;
  224. @include u-flex(column, center, flex-start);
  225. .qrcode-box {
  226. display: inline-block;
  227. padding: 10rpx;
  228. margin: 100rpx 0 30rpx 0;
  229. border: 1rpx solid #FF7700;
  230. position: relative;
  231. }
  232. .qrcode {
  233. height: 300rpx;
  234. width: 300rpx;
  235. }
  236. .qrcodeImg {
  237. height: 300rpx;
  238. width: 300rpx;
  239. }
  240. .qrcode-tips {
  241. height: 38rpx;
  242. margin-bottom: 50rpx;
  243. font-family: PingFang SC, PingFang SC;
  244. font-weight: 400;
  245. font-size: 32rpx;
  246. color: #333333;
  247. }
  248. }
  249. .copybtn {
  250. flex-shrink: 0;
  251. height: 46rpx;
  252. width: 90rpx;
  253. margin-right: 10rpx;
  254. border-radius: 46rpx;
  255. line-height: 46rpx;
  256. text-align: center;
  257. background: rgba(0, 0, 0, 0.1);
  258. font-size: 24rpx;
  259. color: #666;
  260. }
  261. .box {
  262. &-item {
  263. width: 100%;
  264. height: 108rpx;
  265. padding: 0 30rpx;
  266. display: flex;
  267. align-items: center;
  268. justify-content: space-between;
  269. font-family: PingFang SC, PingFang SC;
  270. font-weight: 400;
  271. font-size: 32rpx;
  272. color: #333333;
  273. .arrow_black {
  274. flex-shrink: 0;
  275. height: 48rpx;
  276. width: 48rpx;
  277. }
  278. }
  279. &-iteml {
  280. flex-shrink: 0;
  281. display: flex;
  282. align-items: center;
  283. justify-content: flex-start;
  284. }
  285. &-itemr {
  286. font-size: 28rpx;
  287. display: inline-flex;
  288. align-items: center;
  289. justify-content: flex-start;
  290. }
  291. }
  292. </style>