camera.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  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" @click.stop="takePhoto()">
  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. },
  71. onShow() {
  72. this.srcList = uni.getStorageSync('creditImg');
  73. this.currentIndex = (this.srcList.length - 1)
  74. },
  75. mounted() {},
  76. onUnload() {
  77. uni.removeStorageSync(this.uuidKey);
  78. },
  79. methods: {
  80. openAlbum(){
  81. uni.chooseMedia({
  82. count: this.fileNum, //默认9
  83. mediaType: 'image', //可以指定是原图还是压缩图
  84. sourceType:[ 'album'],
  85. success: (res) => {
  86. tools.showLoading()
  87. console.log(res)
  88. if (res.tempFiles !== undefined) {
  89. res.tempFiles.forEach((file) => {
  90. this.uploadingFile(file.tempFilePath);
  91. })
  92. }
  93. },
  94. fail: (e) => {
  95. console.log(e)
  96. }
  97. });
  98. },
  99. cameraInitdone(res){
  100. console.log(res)
  101. },
  102. goBack() {
  103. tools.leftClick()
  104. },
  105. goToUrl(type) {
  106. if (this.srcList.length < 1) {
  107. tools.error("请上传征信")
  108. } else {
  109. if (type === 1) {
  110. // if (this.uuidKey) {
  111. // // uni.setStorageSync(this.uuidKey, this.srcList);
  112. // // uni.navigateTo({
  113. // // url: `/pages-task/add-client/look-img?key=${this.uuidKey}`,
  114. // // })
  115. // } else {
  116. // this.uuidKey = uuidv4();
  117. // }
  118. // uni.setStorageSync(this.uuidKey, this.srcList);
  119. uni.setStorageSync('creditImg', this.srcList)
  120. uni.navigateTo({
  121. url: `/pages-task/add-client/look-transition`,
  122. })
  123. } else {
  124. console.log(this.srcList);
  125. }
  126. }
  127. },
  128. uploadCreditImage() {
  129. // if (this.isAjax) {
  130. // return false
  131. // }
  132. // this.isAjax = true
  133. // uploadCreditImage({
  134. // 'business_id': this.creditId,
  135. // 'image': this.srcList
  136. // }).then((res) => {
  137. // if (res.code === 1) {
  138. // tools.success(res.msg)
  139. // uni.$emit('newCreditImage', {
  140. // 'credit_sn': res.data.credit_sn
  141. // })
  142. // uni.navigateBack({
  143. // delta: 1
  144. // })
  145. // } else {
  146. // tools.error(res.msg)
  147. // this.isAjax = false
  148. // }
  149. // })
  150. uni.setStorageSync('creditImg', this.srcList)
  151. uni.$emit('creditImg', this.srcList)
  152. uni.navigateBack({
  153. delta: 1
  154. })
  155. },
  156. focusCamera(){
  157. console.log('对焦触发了')
  158. // const ctx = uni.createCameraContext();
  159. const cameraContext = uni.createCameraContext();
  160. // 调用对焦方法
  161. cameraContext.focus();
  162. },
  163. takePhoto() {
  164. const ctx = uni.createCameraContext();
  165. ctx.takePhoto({
  166. quality: 'high',
  167. success: (res) => {
  168. this.uploadingFile(res.tempImagePath)
  169. // this.srcList.push(this.uploadingFile(res.tempImagePath))
  170. // this.$nextTick(() => {
  171. // setTimeout(() => {
  172. // uni.createSelectorQuery().select('#imgId').boundingClientRect((rect) => {
  173. // rect.height即为目标元素的高度
  174. // this.imgHeight = rect.height
  175. // }).exec();
  176. // },500)
  177. // });
  178. console.log(this.srcList);
  179. /* 返回调用页面并把图片URL传递过去 */
  180. /* let pages = getCurrentPages();
  181. let prevPage = pages[pages.length - 2];
  182. prevPage.setData({
  183. "image": res.tempImagePath,
  184. })
  185. uni.navigateBack(); */
  186. /* 调用页面获取图片URL方法 */
  187. /* let pages = getCurrentPages();
  188. let currPage = pages[pages.length-1];
  189. if(typeof(currPage.data.image) != undefined && currPage.data.image != null){
  190. console.log('获取图片:', currPage.data.image)
  191. } */
  192. }
  193. });
  194. },
  195. uploadingFile(file) {
  196. //图片上传
  197. txUploadFile(file).then((res) => {
  198. if (res.Location) {
  199. this.srcList.push(res.Location)
  200. this.currentIndex = (this.srcList.length - 1)
  201. // let that = this
  202. // this.setDate({})
  203. console.log(this.srcList, '当前图片数组');
  204. // return res.Location
  205. // console.log(res,'返回的图片路径');
  206. tools.hideLoading();
  207. } else {
  208. tools.error('上传失败')
  209. }
  210. }).catch((err) => {
  211. tools.hideLoading();
  212. })
  213. },
  214. error(e) {
  215. console.log(e.detail);
  216. }
  217. }
  218. }
  219. </script>
  220. <style lang="scss">
  221. .camera-box {
  222. width: 100%;
  223. height: 100vh;
  224. display: flex;
  225. justify-content: space-between;
  226. .camera-left {
  227. position: relative;
  228. .camera-item {
  229. height: 100vh;
  230. width: 70vw;
  231. position: relative;
  232. }
  233. .back-icons {
  234. position: absolute;
  235. left: 20rpx;
  236. top: 10rpx;
  237. z-index: 10;
  238. width: 25rpx;
  239. height: 25rpx;
  240. }
  241. .scan-img {
  242. opacity: 0.4;
  243. height: 100vh;
  244. width: 70vw;
  245. }
  246. .camera-bg {
  247. opacity: 0.3;
  248. height: 100vh;
  249. width: 70vw;
  250. // border: 34rpx solid #000;
  251. background: transparent;
  252. padding: 34rpx;
  253. box-sizing: border-box;
  254. pointer-events: none;
  255. .photo-frame {
  256. width: 100%;
  257. height: 100%;
  258. border-radius: 20rpx;
  259. border: 8rpx solid #fff;
  260. box-sizing: border-box;
  261. display: flex;
  262. justify-content: center;
  263. // position: relative;
  264. .cover-hr {
  265. width: 4rpx;
  266. height: 100%;
  267. /* background: green; */
  268. // position: absolute;
  269. // left: 50%;
  270. // top: 0;
  271. // margin: 0 auto;
  272. // border-right: 8rpx dashed rgb(0, 255, 0);
  273. .drop {
  274. width: 100%;
  275. height: 8rpx;
  276. border-radius: 20rpx;
  277. background: rgb(0, 255, 0);
  278. margin: 0 0 4rpx 0;
  279. }
  280. .drop:last-child {
  281. margin: 0;
  282. }
  283. }
  284. }
  285. }
  286. .camera-prompt {
  287. width: 100%;
  288. position: absolute;
  289. left: 0;
  290. bottom: 16rpx;
  291. color: #fff;
  292. text-align: center;
  293. }
  294. }
  295. .camera-right {
  296. width: 30vw;
  297. height: 100%;
  298. padding: 20rpx;
  299. box-sizing: border-box;
  300. display: flex;
  301. flex-direction: column;
  302. justify-content: space-between;
  303. .camera-right-top {
  304. width: 100%;
  305. height: 133rpx;
  306. overflow: hidden;
  307. padding: 20rpx 0;
  308. .photos-box {
  309. // margin-left: 10rpx;
  310. // border-radius: 16rpx;
  311. // width: calc(100vw - 500upx - 20rpx);
  312. width: 100%;
  313. height: 100%;
  314. position: relative;
  315. .swiper-box {
  316. border-radius: 20rpx;
  317. }
  318. .photos-hr {
  319. width: 0rpx;
  320. height: 100%;
  321. position: absolute;
  322. left: 50%;
  323. top: 0;
  324. border-right: 2rpx dashed rgb(0, 255, 0);
  325. }
  326. .photos {
  327. width: 100%;
  328. height: 100%;
  329. }
  330. }
  331. }
  332. .camera-but {
  333. //width: 80rpx;
  334. //height: 80rpx;
  335. //line-height: 80rpx;
  336. //border-radius: 50%;
  337. //background-color: red;
  338. display: flex;
  339. justify-content: center;
  340. .camera-img{
  341. width: 80rpx;
  342. height: 80rpx;
  343. border-radius: 50%;
  344. }
  345. }
  346. .scan-buts {
  347. display: flex;
  348. justify-content: space-between;
  349. .scan-text {
  350. width: 45%;
  351. font-size: 13rpx;
  352. text-align: center;
  353. color: #fff;
  354. padding: 10rpx 0;
  355. background: #0FB160;
  356. border-radius: 10rpx;
  357. margin: 15rpx 0 0 0;
  358. // line-height: 60upx;
  359. }
  360. .scan-no {
  361. opacity: 0.7
  362. }
  363. }
  364. .photos-box-blank {
  365. width: 100%;
  366. height: 100%;
  367. background: #ccc;
  368. display: flex;
  369. border-radius: 20rpx;
  370. align-items: center;
  371. justify-content: center;
  372. color: #fff;
  373. }
  374. }
  375. }
  376. </style>