55 <view class =" uni-title" >分享内容</view >
66 <view class =" uni-textarea" >
77 <textarea class =" textarea" v-model =" shareText" />
8- </view >
8+ </view >
99 <view class =" uni-title" >分享图片:</view >
1010 <view class =" uni-uploader" style =" padding :15 upx; background :#FFF ;" >
1111 <view class =" uni-uploader__input-box" v-if =" !image" @tap =" chooseImage" ></view >
3535 </block >
3636 </view >
3737 <!-- #endif -->
38- <!-- #ifdef MP-WEIXIN -->
39- <view class =" uni-btn-v uni-common-mt" >
40- <button type =" primary" open-type =" share" >分享</button >
41- </view >
42- <!-- #endif -->
43- <!-- #ifdef MP-BAIDU -->
38+ <!-- #ifdef MP -->
4439 <view class =" uni-btn-v uni-common-mt" >
4540 <button type =" primary" open-type =" share" >分享</button >
4641 </view >
6964 },
7065 onUnload : function (){
7166 this .shareText = ' uni-app可以同时发布成原生App、微信小程序、H5,邀请你一起体验!' ,
72- this .href = " https://uniapp.dcloud.io" ,
67+ this .href = ' https://uniapp.dcloud.io' ,
7368 this .image = ' ' ;
7469 },
7570 onLoad : function () {
7671 uni .getProvider ({
77- service: " share" ,
72+ service: ' share' ,
7873 success : (e ) => {
79- console .log (" success" , e);
74+ console .log (' success' , e);
8075 let data = []
8176 for (let i = 0 ; i < e .provider .length ; i++ ) {
8277 switch (e .provider [i]) {
116111 });
117112 },
118113 fail : (e ) => {
119- console .log (" 获取登录通道失败" , e);
114+ console .log (' 获取登录通道失败' , e);
120115 uni .showModal ({
121- content: " 获取登录通道失败" ,
116+ content: ' 获取登录通道失败' ,
122117 showCancel: false
123118 })
124119 }
125120 });
126121 },
127122 methods: {
128123 async share (e ) {
129- console .log (" 分享通道:" + e .id + " ; 分享类型:" + this .shareType );
124+ console .log (' 分享通道:' + e .id + ' ; 分享类型:' + this .shareType );
130125
131126 if (! this .shareText && (this .shareType === 1 || this .shareType === 0 )){
132127 uni .showModal ({
133- content: " 分享内容不能为空" ,
128+ content: ' 分享内容不能为空' ,
134129 showCancel: false
135130 })
136131 return ;
137132 }
138133
139134 if (! this .image && (this .shareType === 2 || this .shareType === 0 )){
140135 uni .showModal ({
141- content: " 分享图片不能为空" ,
136+ content: ' 分享图片不能为空' ,
142137 showCancel: false
143138 })
144139 return ;
145140 }
146141
147142 let shareOPtions = {
148143 provider: e .id ,
149- scene: e .type && e .type === ' WXSenceTimeline' ? ' WXSenceTimeline' : " WXSceneSession" , // WXSceneSession”分享到聊天界面,“WXSenceTimeline”分享到朋友圈,“WXSceneFavorite”分享到微信收藏
144+ scene: e .type && e .type === ' WXSenceTimeline' ? ' WXSenceTimeline' : ' WXSceneSession' , // WXSceneSession”分享到聊天界面,“WXSenceTimeline”分享到朋友圈,“WXSceneFavorite”分享到微信收藏
150145 type: this .shareType ,
151146 success : (e ) => {
152- console .log (" success" , e);
147+ console .log (' success' , e);
153148 uni .showModal ({
154- content: " 分享成功" ,
149+ content: ' 分享成功' ,
155150 showCancel: false
156151 })
157152 },
158153 fail : (e ) => {
159- console .log (" fail" , e)
154+ console .log (' fail' , e)
160155 uni .showModal ({
161156 content: e .errMsg ,
162157 showCancel: false
163158 })
164159 },
165160 complete : function (){
166- console .log (" 分享操作结束!" )
161+ console .log (' 分享操作结束!' )
167162 }
168163 }
169164
170165 switch (this .shareType ){
171166 case 0 :
172167 shareOPtions .summary = this .shareText ;
173168 shareOPtions .imageUrl = this .image ;
174- shareOPtions .title = " 欢迎体验uniapp" ;
175- shareOPtions .href = " http://uniapp.dcloud.io" ;
169+ shareOPtions .title = ' 欢迎体验uniapp' ;
170+ shareOPtions .href = ' http://uniapp.dcloud.io' ;
176171 break ;
177172 case 1 :
178173 shareOPtions .summary = this .shareText ;
182177 break ;
183178 case 5 :
184179 shareOPtions .imageUrl = this .image ? this .image : ' https://img-cdn-qiniu.dcloud.net.cn/uniapp/app/share-logo@3.png'
185- shareOPtions .title = " 欢迎体验uniapp" ;
180+ shareOPtions .title = ' 欢迎体验uniapp' ;
186181 shareOPtions .miniProgram = {
187- id: " gh_33446d7f7a26" ,
188- path: " /pages/tabBar/component/component" ,
189- webUrl: " http://uniapp.dcloud.io" ,
182+ id: ' gh_33446d7f7a26' ,
183+ path: ' /pages/tabBar/component/component' ,
184+ webUrl: ' http://uniapp.dcloud.io' ,
190185 type: 0
191186 };
192187 break ;
198193 shareOPtions .imageUrl = await this .compress ();
199194 }
200195 if (shareOPtions .type === 1 && shareOPtions .provider === ' qq' ){// 如果是分享文字到qq,则必须加上href和title
201- shareOPtions .href = " http://uniapp.dcloud.io" ;
202- shareOPtions .title = " 欢迎体验uniapp" ;
196+ shareOPtions .href = ' http://uniapp.dcloud.io' ;
197+ shareOPtions .title = ' 欢迎体验uniapp' ;
203198 }
204199 uni .share (shareOPtions);
205200 },
206201 radioChange (e ){
207- console .log (" type:" + e .detail .value );
202+ console .log (' type:' + e .detail .value );
208203 this .shareType = parseInt (e .detail .value );
209204 },
210205 chooseImage () {
218213 })
219214 },
220215 compress (){// 压缩图片 图文分享要求分享图片大小不能超过20Kb
221- console .log (" 开始压缩" );
216+ console .log (' 开始压缩' );
222217 let img = this .image ;
223218 return new Promise ((res ) => {
224219 var localPath = plus .io .convertAbsoluteFileSystem (img .replace (' file://' , ' ' ));
225220 console .log (' after' + localPath);
226221 // 压缩size
227222 plus .io .resolveLocalFileSystemURL (localPath, (entry ) => {
228223 entry .file ((file ) => {// 可通过entry对象操作图片
229- console .log (" getFile:" + JSON .stringify (file));
224+ console .log (' getFile:' + JSON .stringify (file));
230225 if (file .size > 20480 ) {// 压缩后size 大于20Kb
231226 plus .zip .compressImage ({
232227 src: img,
241236 res (newImg);
242237 }, function (error ) {
243238 uni .showModal ({
244- content: " 分享图片太大,需要请重新选择图片!" ,
239+ content: ' 分享图片太大,需要请重新选择图片!' ,
245240 showCancel: false
246241 })
247242 });
248243 }
249244 });
250245 }, (e ) => {
251- console .log (" Resolve file URL failed: " + e .message );
246+ console .log (' Resolve file URL failed: ' + e .message );
252247 uni .showModal ({
253- content: " 分享图片太大,需要请重新选择图片!" ,
248+ content: ' 分享图片太大,需要请重新选择图片!' ,
254249 showCancel: false
255250 })
256251 });
262257
263258<style >
264259
265- </style >
260+ </style >
0 commit comments