CloudPhoneClipboard.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <template>
  2. <van-dialog v-model="pasteVersionVisible" :show-confirm-button="false" class="paste-version-modal" v-cloak>
  3. <template v-if="pasteVersionList.length">
  4. <div class="tc paste-version-title pre">
  5. <span class="pab">粘贴版</span>
  6. <span class="pab paste-version-clear" @click="deletePasteVersion()"> 清空 </span>
  7. </div>
  8. <div class="paste-version-list">
  9. <div v-for="(item,index) in pasteVersionList" :key="index"
  10. :class="[{'mb-1': index!==pasteVersionList.length - 1}]">
  11. <van-swipe-cell>
  12. <div :class="`copy-value-${index}, ellipsis`" @click="copyPasteVersiontext(item.content)">
  13. {{item.content}}
  14. </div>
  15. <template #right>
  16. <div class="paste-version-delete" @click="deletePasteVersion(item.id)">删除</div>
  17. </template>
  18. </van-swipe-cell>
  19. </div>
  20. </div>
  21. </template>
  22. <template v-else>
  23. <div class="paste-version-empty flex-center-all h100">
  24. <div>
  25. <img :src="jianqieban" alt="">
  26. <div class="tc">剪贴板为空</div>
  27. </div>
  28. </div>
  29. </template>
  30. <img class="pab paste-version-close" :src="closePath" alt="" @click="pasteVersionVisible = false" />
  31. </van-dialog>
  32. </template>
  33. <script>
  34. import Qs from 'qs';
  35. export default {
  36. props: {
  37. doConnectDirectivesWs: {
  38. type: Function,
  39. default: () => {}
  40. }
  41. },
  42. name: 'CloudPhoneClipboard',
  43. data() {
  44. return {
  45. jianqieban: '../rtcEngine/img/jianqieban_pic@2x.png',
  46. closePath: '../rtcEngine/img/guanbi_icon@2x.png',
  47. pasteVersionVisible: false, // 云机粘贴板弹窗
  48. pasteVersionList: [], // 粘贴板列表云机的粘贴板内容
  49. }
  50. },
  51. methods: {
  52. // 粘贴版相关接口
  53. shearContent({ type, params, queryStr }) {
  54. let url = '/public/v5/shear/content'
  55. if (queryStr) url += queryStr
  56. return this.$axios[`$${type}`](url, params);
  57. },
  58. // 内容植入云机的粘贴板
  59. init(text) {
  60. // 判断是否有内容, 有内容先把内容植入云机的粘贴板, 否则直接读取云机的粘贴板
  61. text ? this.openPasteboard(text) : this.getPasteVersion();
  62. },
  63. // 打开粘贴板
  64. async openPasteboard(content, callBack = () => {}) {
  65. try {
  66. await this.shearContent({ type: 'post', params: { content } });
  67. } catch (error) {
  68. console.log('error', error);
  69. } finally {
  70. callBack();
  71. // 获取剪切板
  72. this.getPasteVersion(() => {
  73. this.pasteVersionVisible = true;
  74. })
  75. }
  76. },
  77. // 获取云机粘贴板数据
  78. async getPasteVersion(callBack = () => {}) {
  79. try {
  80. const res = await this.shearContent({ type: 'get' });
  81. this.pasteVersionList = res.data;
  82. callBack(true)
  83. } catch (error) {
  84. callBack(false)
  85. }
  86. },
  87. // 清空全部 或 清除某条
  88. deletePasteVersion(ids){
  89. try {
  90. if (!ids) {
  91. this.$dialog.alert({
  92. title: '提示',
  93. message: '确定清空剪贴板?',
  94. confirmButtonText: '确定',
  95. confirmButtonColor: '#3cc51f',
  96. showCancelButton: true,
  97. beforeClose: (action, done) => {
  98. if (action === 'cancel') done()
  99. if (action === 'confirm') {
  100. fun.bind(this)(done)
  101. }
  102. }
  103. })
  104. return
  105. }
  106. fun.bind(this)()
  107. function fun(callBack = () => {}) {
  108. this.shearContent({
  109. type: 'delete',
  110. queryStr: Qs.stringify(
  111. { ids: ids ? [ids] : this.pasteVersionList.map((v) => v.id) },
  112. { arrayFormat: 'repeat', addQueryPrefix: true },
  113. )
  114. }).then(res => {
  115. if (res.status === 0) {
  116. // 删除成功后重新获取云机粘贴板数据
  117. this.getPasteVersion()
  118. callBack(true)
  119. } else {
  120. callBack(false)
  121. this.$toast(res.msg)
  122. }
  123. }).catch(() => {
  124. callBack(false)
  125. })
  126. }
  127. } catch (error) {
  128. console.log('error', error);
  129. }
  130. },
  131. // 复制粘贴某条数据
  132. async copyPasteVersiontext(text) {
  133. try {
  134. await this.$native.clipboard.writeText(text);
  135. this.$toast('复制成功')
  136. }catch (error) {
  137. console.log('error', error);
  138. this.$toast('复制失败')
  139. }
  140. },
  141. }
  142. }
  143. </script>
  144. <style lang="scss" scoped>
  145. .pre {
  146. position: relative;
  147. }
  148. .pab {
  149. position: absolute;
  150. }
  151. .tc {
  152. text-align: center;
  153. }
  154. .ellipsis {
  155. overflow: hidden;
  156. text-overflow: ellipsis;
  157. white-space: nowrap;
  158. }
  159. .paste-version-modal {
  160. background-color: transparent;
  161. overflow: visible;
  162. ::v-deep .van-dialog__content {
  163. background-color: rgba(0, 0, 0, 0.6);
  164. display: flex;
  165. flex-direction: column;
  166. height: 270px;
  167. padding-bottom: 28px;
  168. border-radius: 16px;
  169. .paste-version-title {
  170. height: 48px;
  171. line-height: 48px;
  172. font-size: 16px;
  173. margin: 0 18px;
  174. &::-webkit-scrollbar {
  175. display: none;
  176. }
  177. & > span:first-child {
  178. top: 50%;
  179. left: 50%;
  180. transform: translate(-50%, -50%);
  181. color: #fff;
  182. }
  183. .paste-version-clear {
  184. position: absolute;
  185. top: 52%;
  186. transform: translateY(-52%);
  187. right: 0;
  188. height: 20px;
  189. line-height: 20px;
  190. padding: 0 10px;
  191. font-size: 12px;
  192. background: #3666f2;
  193. border-radius: 3px;
  194. color: #ffffff;
  195. }
  196. }
  197. .paste-version-list {
  198. flex: 1;
  199. overflow-y: auto;
  200. .van-swipe-cell {
  201. margin: 0 18px;
  202. box-sizing: border-box;
  203. height: 32px;
  204. line-height: 32px;
  205. text-align: center;
  206. font-size: 13px;
  207. color: #666;
  208. background-color: #fff;
  209. border-radius: 5px;
  210. overflow: hidden;
  211. .van-swipe-cell__wrapper {
  212. width: 100%;
  213. height: 100%;
  214. }
  215. .ellipsis {
  216. width: 100%;
  217. height: 100%;
  218. padding: 0 10px;
  219. box-sizing: border-box;
  220. }
  221. }
  222. .paste-version-delete {
  223. width: 40px;
  224. height: 100%;
  225. border: none;
  226. background: #f04646;
  227. color: #fff;
  228. font-size: 12px;
  229. text-align: center;
  230. border-radius: 0 5px 5px 0;
  231. }
  232. }
  233. .paste-version-close {
  234. width: 38px;
  235. height: 38px;
  236. bottom: -20%;
  237. left: 50%;
  238. transform: translateX(-50%);
  239. }
  240. .paste-version-empty img {
  241. width: 128px;
  242. height: 160px;
  243. }
  244. .paste-version-empty > div > div {
  245. margin-top: 9px;
  246. font-size: 15px;
  247. color: #fff;
  248. }
  249. }
  250. .flex-center-all{
  251. display: flex;
  252. align-items: center;
  253. justify-content: center;
  254. }
  255. }
  256. </style>