| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- /**
- * 基于uniapp的api进行二次封装,便于全局管理
- *
- * @copyByUniappApi 全局复制到剪贴板方法
- */
- // 全局复制到剪贴板方法
- export const copyByUniappApi = (data, msg = '已复制到剪贴板') => {
- console.log(".>>>>>复制",data, msg)
- uni.setClipboardData({
- data: data.toString(),
- success: function() {
- uni.showToast({
- title: msg,
- icon: 'none'
- });
- },
- fail: (error) => {
- console.log('error',error);
- }
- });
- }
- // 全局更新购物车角标
- export const updateCartBadge = () => {
- // 检查是否登录,未登录不请求
- const token = uni.getStorageSync('token');
- if (!token) {
- uni.removeTabBarBadge({ index: 2 });
- return;
- }
-
- // 确保 uView http 可用
- if (uni.$u && uni.$u.http) {
- uni.$u.http.post('/token/shop/cart/getCount').then(res => {
- if (res.code == 200) {
- const count = res.data;
- if (count > 0) {
- uni.setTabBarBadge({
- index: 2,
- text: String(count)
- });
- } else {
- uni.removeTabBarBadge({
- index: 2
- });
- }
- }
- }).catch(e => {
- console.log('更新购物车角标失败', e);
- });
- }
- }
|