inspect.nvue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view>
  3. <view style="height: 5px;"></view>
  4. <view class="uni-navigate-item-my" @click="InspctOperate">
  5. <text class="uni-navigate-text-my">质检操作</text>
  6. <text class="uni-navigate-icon-my uni-icon">&#xe470;</text>
  7. </view>
  8. <view style="height: 5px;"></view>
  9. <view class="uni-navigate-item-my" @click="InspectRecordQuery">
  10. <text class="uni-navigate-text-my">质检记录查询</text>
  11. <text class="uni-navigate-icon-my uni-icon">&#xe470;</text>
  12. </view>
  13. <!-- <view class="demo">
  14. <block v-if="imageSrc">
  15. <image :src="imageSrc" class="image" mode="widthFix" @click="previewImage11(1)"></image>
  16. </block>
  17. <block v-else>
  18. <view class="uni-hello-addfile" @click="chooseImage">+ 选择图片</view>
  19. </block>
  20. </view>
  21. <view class="uni-flex uni-row">
  22. <button type="primary" style="-webkit-flex: 1;flex: 1;margin-left: 5px;" @click="deletePic">删除</button>
  23. </view>
  24. <view class="demo">
  25. <block v-if="imageSrc1">
  26. <image :src="imageSrc1" class="image" mode="widthFix" @click="previewImage11(2)"></image>
  27. </block>
  28. </view>
  29. <view class="uni-flex uni-row">
  30. <button type="primary" style="-webkit-flex: 1;flex: 1;margin-left: 5px;" @click="downloadPic">下载图片</button>
  31. </view> -->
  32. </view>
  33. </template>
  34. <script>
  35. // TODO 修复Android v3 加载过慢问题
  36. // #ifdef APP-PLUS
  37. var domModule = weex.requireModule('dom');
  38. domModule.addRule('fontFace', {
  39. 'fontFamily': "uniicons",
  40. 'src': "url('/static/uni.ttf')"
  41. });
  42. // #endif
  43. export default {
  44. data() {
  45. return {
  46. imageSrc: '',
  47. imageSrc1: '',
  48. previewImagePath: '',
  49. previewImagePath1: '',
  50. }
  51. },
  52. onUnload() {
  53. this.imageSrc = '';
  54. },
  55. methods: {
  56. InspctOperate() {
  57. uni.navigateTo({
  58. url:"/pages/Inspect/inspect01",
  59. })
  60. },
  61. InspectRecordQuery() {
  62. // uni.chooseImage({
  63. // count: 6, //默认9
  64. // sizeType: ['original'], //可以指定是原图还是压缩图,默认二者都有
  65. // sourceType: ['camera'], //从相册选择
  66. // success: function (res) {
  67. // console.log(JSON.stringify(res.tempFilePaths));
  68. // }
  69. // });
  70. uni.navigateTo({
  71. url:"/pages/Inspect/inspectRecordQuery",
  72. })
  73. },
  74. chooseImage: function() {
  75. let userMsg = uni.getStorageSync('userInfo')
  76. uni.chooseImage({
  77. count: 1,
  78. sizeType: ['compressed'],
  79. sourceType: ['camera'],
  80. success: (res) => {
  81. // console.log(res.tempFilePaths)
  82. // console.log('chooseImage success, temp path is', res.tempFilePaths[0])
  83. var imageSrc = res.tempFilePaths[0]
  84. this.previewImagePath = res.tempFilePaths
  85. this.imageSrc = imageSrc
  86. uni.uploadFile({
  87. url: getApp().globalData.baseUrl + '/Common/UploadFile',
  88. filePath: imageSrc,
  89. fileType: 'image',
  90. header: { //自定义请求头信息
  91. Authorization: 'Bearer ' + userMsg.tokenStr + ''
  92. },
  93. formData: {
  94. 'FileName': 'test',
  95. 'FileDir': '1111',
  96. 'FileNameType': '1',
  97. 'File' : res.tempFiles[0]
  98. },
  99. name: 'data',
  100. success: (res) => {
  101. // console.log('uploadImage success, res is:', res)
  102. uni.showToast({
  103. title: '上传成功',
  104. icon: 'success',
  105. duration: 1000
  106. })
  107. },
  108. fail: (err) => {
  109. // console.log('uploadImage fail', err);
  110. uni.showModal({
  111. content: err.errMsg,
  112. showCancel: false
  113. });
  114. }
  115. });
  116. },
  117. fail: (err) => {
  118. // console.log('chooseImage fail', err)
  119. // #ifdef MP
  120. uni.getSetting({
  121. success: (res) => {
  122. let authStatus = res.authSetting['scope.album'];
  123. if (!authStatus) {
  124. uni.showModal({
  125. title: '授权失败',
  126. content: 'Hello uni-app需要从您的相册获取图片,请在设置界面打开相关权限',
  127. success: (res) => {
  128. if (res.confirm) {
  129. uni.openSetting()
  130. }
  131. }
  132. })
  133. }
  134. }
  135. })
  136. // #endif
  137. }
  138. })
  139. },
  140. deletePic() {
  141. this.imageSrc = ''
  142. this.imageSrc1 = ''
  143. },
  144. downloadPic() {
  145. let userMsg = uni.getStorageSync('userInfo')
  146. let that = this
  147. uni.downloadFile({
  148. url: getApp().globalData.baseUrl + '/business/Testimage/GetQrCode', //GetTestimage?Id=4
  149. method: 'GET',
  150. header: { //自定义请求头信息
  151. Authorization: 'Bearer ' + userMsg.tokenStr + ''
  152. },
  153. success: res => {
  154. // console.log(res)
  155. // const arrayBuffer = new Uint8Array(res.data)
  156. // this.imageSrc1 = 'data:image/png;base64,' + uni.arrayBufferToBase64(arrayBuffer);
  157. // this.previewImagePath1 = this.imageSrc1
  158. this.imageSrc1 = res.tempFilePath
  159. uni.saveFile({
  160. tempFilePath: res.tempFilePath,
  161. success: function (res) {
  162. var savedFilePath = res.savedFilePath;
  163. that.previewImagePath1 = res.savedFilePath
  164. }
  165. });
  166. },
  167. fail: (err) => {
  168. // console.log(err)
  169. }
  170. });
  171. },
  172. previewImage11(res) {
  173. // ToDo: 暂未实现 从后端获取图片并预览大图 孙亚龙
  174. // 预览图片
  175. uni.previewImage({
  176. urls: res == 1 ? this.previewImagePath : this.previewImagePath1
  177. });
  178. }
  179. }
  180. }
  181. </script>
  182. <style lang="scss">
  183. @import '../../../common/uni-nvue.css';
  184. .image {
  185. width: 100%;
  186. }
  187. .demo {
  188. background: #FFF;
  189. padding: 50rpx;
  190. }
  191. </style>