{"id":877,"date":"2022-06-16T09:49:53","date_gmt":"2022-06-16T01:49:53","guid":{"rendered":"https:\/\/usei.cn\/?p=877"},"modified":"2022-06-16T09:49:54","modified_gmt":"2022-06-16T01:49:54","slug":"uni-%e7%bb%84%e4%bb%b6-%e6%82%ac%e6%b5%ae%e7%90%83","status":"publish","type":"post","link":"https:\/\/usei.cn\/index.php\/2022\/06\/16\/uni-%e7%bb%84%e4%bb%b6-%e6%82%ac%e6%b5%ae%e7%90%83\/","title":{"rendered":"uni-\u7ec4\u4ef6-\u60ac\u6d6e\u7403"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/usei.cn\/wp-content\/uploads\/2022\/06\/1655344093372.png\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/usei.cn\/wp-content\/uploads\/2022\/06\/1655344093372.png'><img class=\"lazyload lazyload-style-3\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  loading=\"lazy\" decoding=\"async\" width=\"376\" height=\"668\" data-original=\"https:\/\/usei.cn\/wp-content\/uploads\/2022\/06\/1655344093372.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\" class=\"wp-image-878\"  sizes=\"auto, (max-width: 376px) 100vw, 376px\" \/><\/div><\/a><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">\u8c03\u7528<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- \u60ac\u6d6e\u7403-\u626b\u4e00\u626b -->\n&lt;drag-button @btnClick=\"scanShop\" :isDock=\"true\">\n   &lt;u-icon name=\"scan\" style=\"font-size: 40rpx;\">&lt;\/u-icon>\n&lt;\/drag-button>\n&lt;!-- \u60ac\u6d6e\u7403-\u626b\u4e00\u626b --><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u7ec4\u4ef6\u4ee3\u7801<\/h3>\n\n\n\n<p>components\/drag-button.vue<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;template>\r\n\t&lt;view>\r\n\t\t&lt;view\r\n\t\t\tid=\"_drag_button\"\r\n\t\t\tclass=\"drag\"\r\n\t\t\t:style=\"'left: ' + left + 'px; top:' + top + 'px;'\"\r\n\t\t\t@touchstart=\"touchstart\"\r\n\t\t\t@touchmove.stop.prevent=\"touchmove\"\r\n\t\t\t@touchend.stop=\"touchend\"\r\n\t\t\t@click.stop.prevent=\"click\"\r\n\t\t\t:class=\"{ transition: isDock &amp;&amp; !isMove }\"\r\n\t\t>\r\n\t\t\t&lt;slot>&lt;text>{{ text }}&lt;\/text>&lt;\/slot>\r\n\t\t&lt;\/view>\r\n\t&lt;\/view>\r\n&lt;\/template>\r\n\r\n&lt;script>\r\nexport default {\r\n\tname: 'drag-button',\r\n\tprops: {\r\n\t\tisDock: { \/\/ \u662f\u5426\u81ea\u52a8\u8d34\u8fb9\r\n\t\t\ttype: Boolean,\r\n\t\t\tdefault: false\r\n\t\t},\r\n\t\texistTabBar: {\r\n\t\t\ttype: Boolean,\r\n\t\t\tdefault: false\r\n\t\t}\r\n\t},\r\n\tdata() {\r\n\t\treturn {\r\n\t\t\ttop: 0,\r\n\t\t\tleft: 0,\r\n\t\t\twidth: 0,\r\n\t\t\theight: 0,\r\n\t\t\toffsetWidth: 0,\r\n\t\t\toffsetHeight: 0,\r\n\t\t\twindowWidth: 0,\r\n\t\t\twindowHeight: 0,\r\n\t\t\tisMove: true,\r\n\t\t\tedge: 10,\r\n\t\t\ttext: '\u516c\u544a' \/\/\u6b64\u5904\u81ea\u5b9a\u4e49\u6309\u94ae\u6587\u5b57(1-3\u4e2a\u6c49\u5b57)\r\n\t\t};\r\n\t},\r\n\tmounted() {\r\n\t\tconst sys = uni.getSystemInfoSync();\r\n\r\n\t\tthis.windowWidth = sys.windowWidth;\r\n\t\tthis.windowHeight = sys.windowHeight;\r\n\r\n\t\t\/\/ #ifdef APP-PLUS\r\n\t\tthis.existTabBar &amp;&amp; (this.windowHeight -= 50);\r\n\t\t\/\/ #endif\r\n\t\tif (sys.windowTop) {\r\n\t\t\tthis.windowHeight += sys.windowTop;\r\n\t\t}\r\n\t\t\/\/ console.log(sys);\r\n\t\tconst query = uni.createSelectorQuery().in(this);\r\n\t\tquery\r\n\t\t\t.select('#_drag_button')\r\n\t\t\t.boundingClientRect(data => {\r\n\t\t\t\tthis.width = data.width;\r\n\t\t\t\tthis.height = data.height;\r\n\t\t\t\tthis.offsetWidth = data.width \/ 2;\r\n\t\t\t\tthis.offsetHeight = data.height \/ 2;\r\n\t\t\t\tthis.left = this.windowWidth - this.width - this.edge;\r\n\t\t\t\tthis.top = ((this.windowHeight - this.height - this.edge) * 3) \/ 4;\r\n\t\t\t})\r\n\t\t\t.exec();\r\n\t},\r\n\tmethods: {\r\n\t\tclick() {\r\n\t\t\tthis.$emit('btnClick');\r\n\t\t},\r\n\t\ttouchstart(e) {\r\n\t\t\tthis.$emit('btnTouchstart');\r\n\t\t},\r\n\t\ttouchmove(e) {\r\n\t\t\t\/\/ \u5355\u6307\u89e6\u6478\r\n\t\t\tif (e.touches.length !== 1) {\r\n\t\t\t\treturn false;\r\n\t\t\t}\r\n\r\n\t\t\tthis.isMove = true;\r\n\r\n\t\t\tthis.left = e.touches&#91;0].clientX - this.offsetWidth;\r\n\r\n\t\t\tlet clientY = e.touches&#91;0].clientY - this.offsetHeight;\r\n\t\t\t\/\/ #ifdef H5\r\n\t\t\tclientY += this.height;\r\n\t\t\t\/\/ #endif\r\n\t\t\tlet edgeBottom = this.windowHeight - this.height - this.edge;\r\n\r\n\t\t\t\/\/ \u4e0a\u4e0b\u89e6\u53ca\u8fb9\u754c\r\n\t\t\tif (clientY &lt; this.edge) {\r\n\t\t\t\tthis.top = this.edge;\r\n\t\t\t} else if (clientY > edgeBottom) {\r\n\t\t\t\tthis.top = edgeBottom;\r\n\t\t\t} else {\r\n\t\t\t\tthis.top = clientY;\r\n\t\t\t}\r\n\t\t},\r\n\t\ttouchend(e) {\r\n\t\t\tif (this.isDock) {\r\n\t\t\t\tlet edgeRigth = this.windowWidth - this.width - this.edge;\r\n\r\n\t\t\t\tif (this.left &lt; this.windowWidth \/ 2 - this.offsetWidth) {\r\n\t\t\t\t\tthis.left = this.edge;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tthis.left = edgeRigth;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tthis.isMove = false;\r\n\r\n\t\t\tthis.$emit('btnTouchend');\r\n\t\t}\r\n\t}\r\n};\r\n&lt;\/script>\r\n\r\n&lt;style lang=\"scss\">\r\n.drag {\r\n\tdisplay: flex;\r\n\tjustify-content: center;\r\n\talign-items: center;\r\n\tbackground-color: rgba(0, 0, 0, 0.4);\r\n\tbox-shadow: 0 0 6upx rgba(0, 0, 0, 0.3);\r\n\tcolor: $uni-text-color-inverse;\r\n\twidth: 80upx;\r\n\theight: 80upx;\r\n\tborder-radius: 50%;\r\n\tposition: fixed;\r\n\tz-index: 99;\r\n\r\n\t&amp;.transition {\r\n\t\ttransition: left 0.3s ease, top 0.3s ease;\r\n\t}\r\n}\r\n&lt;\/style><\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u8c03\u7528 \u7ec4\u4ef6\u4ee3\u7801 components\/drag-button.vue<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73,8],"tags":[],"class_list":["post-877","post","type-post","status-publish","format-standard","hentry","category-uni","category-frontend"],"_links":{"self":[{"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/posts\/877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/comments?post=877"}],"version-history":[{"count":1,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/posts\/877\/revisions"}],"predecessor-version":[{"id":879,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/posts\/877\/revisions\/879"}],"wp:attachment":[{"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/media?parent=877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/categories?post=877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/usei.cn\/index.php\/wp-json\/wp\/v2\/tags?post=877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}