takePhoto.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <template>
  2. <view>
  3. <camera device-position="back" flash="off" class="camera"></camera>
  4. <button type="primary" class="takeBtn" @click="takePhoto">拍摄</button>
  5. </view>
  6. </template>
  7. <script>
  8. export default{
  9. data(){
  10. return {
  11. }
  12. },
  13. onLoad(){
  14. },
  15. methods:{
  16. takePhoto(){
  17. uni.authorize({
  18. scope:"scope.camera",
  19. success(){
  20. let ctx=uni.createCameraContext();
  21. ctx.takePhoto({
  22. quality:"high",
  23. success(res){
  24. uni.saveImageToPhotosAlbum({
  25. filePath: res.tempImagePath,
  26. success: function () {
  27. uni.navigateBack({
  28. delta:1
  29. })
  30. }
  31. });
  32. },
  33. fail(){
  34. },
  35. complete(){
  36. }
  37. })
  38. },
  39. fail(){
  40. },
  41. complete(){
  42. }
  43. })
  44. }
  45. }
  46. }
  47. </script>
  48. <style lang="scss">
  49. page{
  50. width: 100%;
  51. height: 100%;
  52. background: $uni-bg-color-normal;
  53. }
  54. .camera{
  55. display: block;
  56. width: 100%;
  57. height: 712rpx;
  58. background: rgba(0,0,0,.48);
  59. margin-bottom: 60rpx;
  60. }
  61. .takeBtn{
  62. width: calc(100% - 60rpx);
  63. margin: 0 30rpx;
  64. background: $uni-btn-bg-color !important;
  65. height: 76rpx;
  66. line-height: 76rpx;
  67. }
  68. </style>