| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- <template>
- <view class="column centerV">
- <view class="codeimg">
- <view v-if="wechatImg!=null" class="centerV">
- <image :src="wechatImg" style="width: 100%;" mode="aspectFit" :show-menu-by-longpress="true" ></image>
- <view class="centerV">点击保存图片至本地!</view>
- </view>
- <view v-else>
- <image src="https://zkzh-2025.oss-cn-beijing.aliyuncs.com/shop/images/no_data.png" style="width: 100%;"
- mode="aspectFill"></image>
- <view class="centerV">暂无二维码,请点击生成二维码</view>
- </view>
- </view>
- <view class="centerV generate" @click="generatecode" v-if="wechatImg==null">点击生成</view>
- <view class="centerV generate" @click="saveImage" v-else>保存图片</view>
- </view>
- </template>
- <script>
- import {
- getcomapycode,
- generateComapycode
- } from '@/api/companyUser'
- export default {
- data() {
- return {
- wechatImg: null,
- companyId: '',
- companyUserId:null
- }
- },
- onLoad(option) {
- this.companyId = option.companyId
- this.companyUserId=option.companyUserId
- this.getcomapycodes()
- },
- methods: {
- saveImage() {
- wx.downloadFile({
- url: this.wechatImg, //仅为示例,并非真实的资源
- success (res) {
- console.log(res)
- // 只要服务器有响应数据,就会把响应内容写入文件并进入 success 回调,业务需要自行判断是否下载到了想要的内容
- if (res.statusCode === 200) {
- wx.saveImageToPhotosAlbum({
- filePath: res.tempFilePath,
- success: function(res) {
- wx.showToast({
- title: '已保存至相册',
- icon: 'none',
- duration: 1000
- })
- },
- fail: function(err) {
- console.log(err);
- wx.showToast({
- title: '保存失败',
- icon: 'none',
- duration: 1000
- })
- }
- })
- wx.playVoice({
- filePath: res.tempFilePath
- })
- }
- }
- })
-
- },
- generatecode() {
- const data = {
- companyId: this.companyId,
- appId: wx.getAccountInfoSync().miniProgram.appId,
- companyUserId:this.companyUserId
- }
- generateComapycode(data).then(res => {
- if (res.code == 200) {
- this.getcomapycodes()
- console.log(res)
- } else {
- uni.showToast({
- icon: 'none',
- title: res.msg,
- });
- }
- })
- },
- getcomapycodes() {
- const data = {
- companyId: this.companyId,
- companyUserId:this.companyUserId,
- appId:wx.getAccountInfoSync().miniProgram.appId,
- }
- getcomapycode(data).then(res => {
- if (res.code == 200) {
- // 核心js代码:
- this.wechatImg = res.data
- } else {
- uni.showToast({
- icon: 'none',
- title: res.msg,
- });
- }
- })
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .codeimg {
- width: 80%;
- margin: 40rpx 0;
- }
- .generate {
- background-color: #2BC7B9;
- width: 70%;
- margin: 0 auto;
- border-radius: 40rpx;
- padding: 20rpx 0;
- color: #fff;
- margin-top: 30rpx;
- }
- </style>
|