camera.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. <template>
  2. <view class="camera-box">
  3. <!-- <Nav textContents=" " navBackgroundColor="transparent"></Nav> -->
  4. <view class="camera-left" >
  5. <!-- <uni-icons class="back-icons" color="#000" type="back" size="24" @click="goBack"></uni-icons> -->
  6. <camera class="camera-item" device-position="back" flash="auto" @error="error" @initdone="cameraInitdone">
  7. <!-- <cover-image src="../static/scan-frame/scan-img.png" class="scan-img"></cover-image> -->
  8. <cover-image src="@/static/img/login/fh.png" @click="goBack" class="back-icons"></cover-image>
  9. <cover-view class="camera-bg" @click.stop="focusCamera" >
  10. <cover-view class="photo-frame">
  11. <cover-view class="cover-hr">
  12. <cover-view class="drop" v-for="(item,index) in 30"></cover-view>
  13. </cover-view>
  14. </cover-view>
  15. </cover-view>
  16. <cover-view class="camera-prompt">
  17. 请以页面顺序扫描。绿色虚线为裁剪线,请对齐征信报告中线
  18. </cover-view>
  19. </camera>
  20. </view>
  21. <view class="camera-right ">
  22. <view class="camera-right-top">
  23. <swiper class="photos-box" circular :indicator-dots="false" :autoplay="false" interval="2000"
  24. :duration="duration" v-if="srcList.length>0" indicator-dots="true" :current="currentIndex">
  25. <swiper-item class="swiper-box" v-for="(item,index) in srcList" key="index">
  26. <image mode="aspectFill" ref="imgRef" id="imgId" class="photos" :src="item"></image>
  27. <view v-show="srcList.length>0" class="photos-hr"></view>
  28. </swiper-item>
  29. </swiper>
  30. <view class="photos-box-blank" v-else>
  31. 暂无图片
  32. </view>
  33. </view>
  34. <!-- <view class="">
  35. <view v-show="src" class="photos-hr"></view>
  36. </view> -->
  37. <view class="">
  38. <view class="camera-but">
  39. <image class="camera-img" src="/page_task/static/img/information/photograph.png" mode="aspectFill"></image>
  40. </view>
  41. <view class="scan-buts">
  42. <view class="scan-text" @click="openAlbum(1)">相册</view>
  43. <view :class="{'scan-no':srcList.length<=0}" class="scan-text" @click="uploadCreditImage()">上传
  44. </view>
  45. </view>
  46. </view>
  47. </view>
  48. </view>
  49. </template>
  50. <script>
  51. import txUploadFile from "@/service/txOssSts";
  52. import tools from "@/service/tools";
  53. export default {
  54. components: {
  55. },
  56. data() {
  57. return {
  58. srcList: [
  59. // 'https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/app-serve/2024-2-26/gtrhdaj99s.jpg',
  60. // 'https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/app-serve/2024-2-26/gtrhdyd39w.jpg',
  61. ],
  62. currentIndex: 0,
  63. uuidKey: '',
  64. duration: '',
  65. isAjax: false,
  66. creditId: '',
  67. }
  68. },
  69. onLoad(data) {
  70. console.log(data, '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^');
  71. if (data.id) {
  72. // this.creditId = data.id
  73. // this.getCreditImage(data.credit_sn)
  74. this.srcList = uni.getStorageSync('creditImg');
  75. }
  76. uni.$on('newCameraImages', (res) => {
  77. // this.srcList = uni.getStorageSync(res);
  78. // console.log(this.srcList, "OOOOOOOOOOOOOOOOOOOOOOOOO");
  79. // this.currentIndex = (this.srcList.length - 1)
  80. // this.uuidKey = res
  81. // uni.removeStorageSync(this.uuidKey);
  82. this.srcList = uni.getStorageSync('creditImg');
  83. this.currentIndex = (this.srcList.length - 1)
  84. })
  85. },
  86. mounted() {},
  87. onUnload() {
  88. uni.removeStorageSync(this.uuidKey);
  89. },
  90. methods: {
  91. openAlbum(){
  92. uni.chooseImage({
  93. count: this.fileNum, //默认9
  94. sizeType: 'compressed', //可以指定是原图还是压缩图
  95. sourceType: 'album',
  96. success: (res) => {
  97. tools.showLoading()
  98. if (res.tempFiles !== undefined) {
  99. res.tempFiles.forEach((file) => {
  100. this.uploadingFile(file.path);
  101. })
  102. }
  103. },
  104. fail: (e) => {
  105. console.log(e)
  106. }
  107. });
  108. },
  109. cameraInitdone(res){
  110. console.log(res)
  111. },
  112. goBack() {
  113. tools.leftClick()
  114. },
  115. goToUrl(type) {
  116. if (this.srcList.length < 1) {
  117. tools.error("请上传征信")
  118. } else {
  119. if (type === 1) {
  120. // if (this.uuidKey) {
  121. // // uni.setStorageSync(this.uuidKey, this.srcList);
  122. // // uni.navigateTo({
  123. // // url: `/pages-task/add-client/look-img?key=${this.uuidKey}`,
  124. // // })
  125. // } else {
  126. // this.uuidKey = uuidv4();
  127. // }
  128. // uni.setStorageSync(this.uuidKey, this.srcList);
  129. uni.setStorageSync('creditImg', this.srcList)
  130. uni.navigateTo({
  131. url: `/pages-task/add-client/look-transition`,
  132. })
  133. } else {
  134. console.log(this.srcList);
  135. }
  136. }
  137. },
  138. uploadCreditImage() {
  139. // if (this.isAjax) {
  140. // return false
  141. // }
  142. // this.isAjax = true
  143. // uploadCreditImage({
  144. // 'business_id': this.creditId,
  145. // 'image': this.srcList
  146. // }).then((res) => {
  147. // if (res.code === 1) {
  148. // tools.success(res.msg)
  149. // uni.$emit('newCreditImage', {
  150. // 'credit_sn': res.data.credit_sn
  151. // })
  152. // uni.navigateBack({
  153. // delta: 1
  154. // })
  155. // } else {
  156. // tools.error(res.msg)
  157. // this.isAjax = false
  158. // }
  159. // })
  160. uni.setStorageSync('creditImg', this.srcList)
  161. uni.$emit('creditImg', this.srcList)
  162. uni.navigateBack({
  163. delta: 1
  164. })
  165. },
  166. focusCamera(){
  167. console.log('对焦触发了')
  168. // const ctx = uni.createCameraContext();
  169. const cameraContext = uni.createCameraContext();
  170. // 调用对焦方法
  171. cameraContext.focus();
  172. },
  173. takePhoto() {
  174. const ctx = uni.createCameraContext();
  175. ctx.takePhoto({
  176. quality: 'high',
  177. success: (res) => {
  178. this.uploadingFile(res.tempImagePath)
  179. // this.srcList.push(this.uploadingFile(res.tempImagePath))
  180. // this.$nextTick(() => {
  181. // setTimeout(() => {
  182. // uni.createSelectorQuery().select('#imgId').boundingClientRect((rect) => {
  183. // rect.height即为目标元素的高度
  184. // this.imgHeight = rect.height
  185. // }).exec();
  186. // },500)
  187. // });
  188. console.log(this.srcList);
  189. /* 返回调用页面并把图片URL传递过去 */
  190. /* let pages = getCurrentPages();
  191. let prevPage = pages[pages.length - 2];
  192. prevPage.setData({
  193. "image": res.tempImagePath,
  194. })
  195. uni.navigateBack(); */
  196. /* 调用页面获取图片URL方法 */
  197. /* let pages = getCurrentPages();
  198. let currPage = pages[pages.length-1];
  199. if(typeof(currPage.data.image) != undefined && currPage.data.image != null){
  200. console.log('获取图片:', currPage.data.image)
  201. } */
  202. }
  203. });
  204. },
  205. uploadingFile(file) {
  206. //图片上传
  207. txUploadFile(file).then((res) => {
  208. if (res.Location) {
  209. this.srcList.push(res.Location)
  210. this.currentIndex = (this.srcList.length - 1)
  211. // let that = this
  212. // this.setDate({})
  213. console.log(this.srcList, '当前图片数组');
  214. // return res.Location
  215. // console.log(res,'返回的图片路径');
  216. tools.hideLoading();
  217. } else {
  218. tools.error('上传失败')
  219. }
  220. }).catch((err) => {
  221. tools.hideLoading();
  222. })
  223. },
  224. error(e) {
  225. console.log(e.detail);
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang="scss">
  231. .camera-box {
  232. width: 100%;
  233. height: 100vh;
  234. display: flex;
  235. justify-content: space-between;
  236. .camera-left {
  237. position: relative;
  238. .camera-item {
  239. height: 100vh;
  240. width: 70vw;
  241. position: relative;
  242. }
  243. .back-icons {
  244. position: absolute;
  245. left: 20rpx;
  246. top: 10rpx;
  247. z-index: 10;
  248. width: 25rpx;
  249. height: 25rpx;
  250. }
  251. .scan-img {
  252. opacity: 0.4;
  253. height: 100vh;
  254. width: 70vw;
  255. }
  256. .camera-bg {
  257. opacity: 0.3;
  258. height: 100vh;
  259. width: 70vw;
  260. // border: 34rpx solid #000;
  261. background: transparent;
  262. padding: 34rpx;
  263. box-sizing: border-box;
  264. pointer-events: none;
  265. .photo-frame {
  266. width: 100%;
  267. height: 100%;
  268. border-radius: 20rpx;
  269. border: 8rpx solid #fff;
  270. box-sizing: border-box;
  271. display: flex;
  272. justify-content: center;
  273. // position: relative;
  274. .cover-hr {
  275. width: 4rpx;
  276. height: 100%;
  277. /* background: green; */
  278. // position: absolute;
  279. // left: 50%;
  280. // top: 0;
  281. // margin: 0 auto;
  282. // border-right: 8rpx dashed rgb(0, 255, 0);
  283. .drop {
  284. width: 100%;
  285. height: 8rpx;
  286. border-radius: 20rpx;
  287. background: rgb(0, 255, 0);
  288. margin: 0 0 4rpx 0;
  289. }
  290. .drop:last-child {
  291. margin: 0;
  292. }
  293. }
  294. }
  295. }
  296. .camera-prompt {
  297. width: 100%;
  298. position: absolute;
  299. left: 0;
  300. bottom: 16rpx;
  301. color: #fff;
  302. text-align: center;
  303. }
  304. }
  305. .camera-right {
  306. width: 30vw;
  307. height: 100%;
  308. padding: 20rpx;
  309. box-sizing: border-box;
  310. display: flex;
  311. flex-direction: column;
  312. justify-content: space-between;
  313. .camera-right-top {
  314. width: 100%;
  315. height: 133rpx;
  316. overflow: hidden;
  317. padding: 20rpx 0;
  318. .photos-box {
  319. // margin-left: 10rpx;
  320. // border-radius: 16rpx;
  321. // width: calc(100vw - 500upx - 20rpx);
  322. width: 100%;
  323. height: 100%;
  324. position: relative;
  325. .swiper-box {
  326. border-radius: 20rpx;
  327. }
  328. .photos-hr {
  329. width: 0rpx;
  330. height: 100%;
  331. position: absolute;
  332. left: 50%;
  333. top: 0;
  334. border-right: 2rpx dashed rgb(0, 255, 0);
  335. }
  336. .photos {
  337. width: 100%;
  338. height: 100%;
  339. }
  340. }
  341. }
  342. .camera-but {
  343. //width: 80rpx;
  344. //height: 80rpx;
  345. //line-height: 80rpx;
  346. //border-radius: 50%;
  347. //background-color: red;
  348. display: flex;
  349. justify-content: center;
  350. .camera-img{
  351. width: 80rpx;
  352. height: 80rpx;
  353. border-radius: 50%;
  354. }
  355. }
  356. .scan-buts {
  357. display: flex;
  358. justify-content: space-between;
  359. .scan-text {
  360. width: 45%;
  361. font-size: 13rpx;
  362. text-align: center;
  363. color: #fff;
  364. padding: 10rpx 0;
  365. background: #0FB160;
  366. border-radius: 10rpx;
  367. margin: 15rpx 0 0 0;
  368. // line-height: 60upx;
  369. }
  370. .scan-no {
  371. opacity: 0.7
  372. }
  373. }
  374. .photos-box-blank {
  375. width: 100%;
  376. height: 100%;
  377. background: #ccc;
  378. display: flex;
  379. border-radius: 20rpx;
  380. align-items: center;
  381. justify-content: center;
  382. color: #fff;
  383. }
  384. }
  385. }
  386. </style>