Blame view

pages/API/clipboard/clipboard.vue 1.95 KB
4b045f7c   刘淇   江阴初始化项目
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
  <template>
  	<view>
  		<page-head :title="title"></page-head>
  		<view class="uni-padding-wrap">
  			<view class="uni-title">请输入剪贴板内容</view>
  			<view class="uni-list">
  				<view class="uni-list-cell">
  					<input class="uni-input" type="text" placeholder="请输入剪贴板内容" :value="data" @input="dataChange"/>
  				</view>
  			</view>
  			<view class="uni-btn-v">
  				<button type="primary" @click="setClipboard">存储数据</button>
  				<button @tap="getClipboard">读取数据</button>
  			</view>
  		</view>
  	</view>
  </template>
  <script>
  	export default {
  		data() {
  			return {
  				title: 'get/setClipboardData',
  				data: ''
  			}
  		},
  		methods: {
  			dataChange: function (e) {
  				this.data = e.detail.value
  			},
  			getClipboard: function () {
  				uni.getClipboardData({
  					success: (res) => {
  						console.log(res.data);
  						const content = res.data ? '剪贴板内容为:' + res.data : '剪贴板暂无内容';
  						uni.showModal({
  							content,
  							title: '读取剪贴板',
  							showCancel: false
  						})
  					},
  					fail: () => {
  						uni.showModal({
  							content: '读取剪贴板失败!',
  							showCancel: false
  						})
  					}
  				});
  			},
  			setClipboard: function () {
  				var data = this.data;
  				if (data.length === 0) {
  					uni.showModal({
  						title: '设置剪贴板失败',
  						content: '内容不能为空',
  						showCancel: false
  					})
  				} else {
  					uni.setClipboardData({
  						data: data,
  						success: () => {
  							// 成功处理
  							// #ifdef MP-ALIPAY || MP-BAIDU || MP-TOUTIAO
  							uni.showToast({
  								title: '设置剪贴板成功',
  								icon: "success",
  								mask: !1
  							})
  							// #endif
  						},
  						fail: () => {
  							// 失败处理
  							// #ifdef MP-ALIPAY || MP-BAIDU || MP-TOUTIAO
  							uni.showToast({
  								title: '储存数据失败!',
  								icon: "none",
  								mask: !1
  							})
  							// #endif
  						}
  					});
  				}
  			}
  		}
  	}
  </script>
  
  <style>
  	
  </style>