camera.vue 10 KB

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