index.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <template>
  2. <view class="box-data" @click="chooseMessageFile">
  3. 测试环境开始
  4. </view>
  5. </template>
  6. <script>
  7. import tools from "@/service/tools";
  8. import jWeixin from "wecomjsdk"
  9. import wxJs from "jweixin-module"
  10. export default {
  11. components: {
  12. },
  13. data() {
  14. return {
  15. }
  16. },
  17. watch: {
  18. },
  19. mounted() {
  20. tools.wxInitialize(['chooseImage'])
  21. tools.wxAgentInitialize(['chooseMessageFile','invoke'])
  22. },
  23. methods: {
  24. chooseMessageFile(){
  25. console.log('chooseMessageFile:事件开始触发')
  26. wxJs.chooseImage({
  27. count: 1, // 默认9
  28. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  29. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  30. defaultCameraMode: "batch", //表示进入拍照界面的默认模式,目前有normal与batch两种选择,normal表示普通单拍模式,batch表示连拍模式,不传该参数则为normal模式。从3.0.26版本开始支持front和batch_front两种值,其中front表示默认为前置摄像头单拍模式,batch_front表示默认为前置摄像头连拍模式。(注:用户进入拍照界面仍然可自由切换两种模式)
  31. isSaveToAlbum: 1, //整型值,0表示拍照时不保存到系统相册,1表示自动保存,默认值是1
  32. success: function (res) {
  33. let localIds = res.localIds; // 返回选定照片的本地ID列表,
  34. console.log(localIds)
  35. // andriod中localId可以作为img标签的src属性显示图片;
  36. // iOS应当使用 getLocalImgData 获取图片base64数据,从而用于img标签的显示(在img标签内使用 wx.chooseImage 的 localid 显示可能会不成功)
  37. }
  38. });
  39. // jWeixin.invoke('chooseMessageFile', {
  40. // count: 10,
  41. // type: 'image',
  42. // }, function(res) {
  43. // console.log(res)
  44. // // 这里是回调函数
  45. // if (res.err_msg == "chooseMessageFile:ok"){
  46. // const tempFiles = res.tempFiles
  47. // }
  48. // });
  49. }
  50. },
  51. }
  52. </script>
  53. <style lang="scss" scoped>
  54. </style>