• uniapp之actionsheet 自定义组件


    uniapp本身自带的actionsheet太丑,不够美观。闲着也是闲着,自己实现了一个类似的选择器。

    支持功能:

    1、左对齐

    2、右对齐

    3、居中

    4、可加图标

    下面贴出使用教程:

     组件实现代码:在你项目合适的目录中创建一个名为zxp-uniActionSheet.vue的组件文件,一般位于项目的components目录中,注意目录及页面中的引用位置!

    或者直接通过hbuilderx引入到你的项目中!

    actionsheet 自定义组件 - DCloud 插件市场

    1. <script>
    2. export default {
    3. data() {
    4. return {
    5. viewTitle: null,
    6. selectIndex: 0,
    7. dataList: [],
    8. modalAnimation: false,
    9. checkIconData: ''
    10. };
    11. },
    12. props: {
    13. showSheetView: {
    14. type: Boolean,
    15. default: false
    16. },
    17. optionsList: {
    18. type: Array,
    19. default: []
    20. },
    21. titleKey: {
    22. type: String,
    23. default: ""
    24. },
    25. iconKey: {
    26. type: String,
    27. default: ""
    28. },
    29. defaultIndex: {
    30. type: Number,
    31. default: 0
    32. },
    33. sheetTitle: {
    34. type: String,
    35. default: "请选择"
    36. },
    37. alignment: {
    38. type: String,
    39. default: "center"
    40. },
    41. displayCheckedIcon: {
    42. type: Boolean,
    43. default: false
    44. },
    45. autoConfirm: {
    46. type: Boolean,
    47. default: true
    48. },
    49. },
    50. created() {
    51. this.viewTitle = this.sheetTitle
    52. this.selectIndex = this.defaultIndex
    53. this.dataList = this.optionsList
    54. let icon = 'iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAAAXNSR0IArs4c6QAAAchJREFUeF7tmUFywjAMReXQi+QkDceCLgqLwrHgJrkIE3fClA5DE5AcyZJrsXZivecvOwkBKv+FyvnBBXgCKjfgLVB5AHwT9BbwFqjcgLdA5QHwU8BbwFugcgP/ogWar34HAT4jwHkVYH/ZtGfsuhYvIBz6UwDo7oGHbYvmQg/EGs05bgp+nL8JsMamoFgBc/BVCHgGDxH2w0e7wyaxuARwwo+SihLADV+UAAn4YgRIwRchQBKeLODt2HfY8xW7Cz8bJw2PFjCCDxFOv8USj5oUGTng0QImixGUkAseLaA59HFyFQUk5ITHC/h525KWkBseLeA6cOKti3NPkL7/3D5EehKUKlLqvpjNlyRAIgma8KQWuLfJVTTXfTArzdICnBIswCcn4CYiFSL1uiUrzZ6AVAmW4BcngCrBGjybAMzpEAO8P3695XyOSG0P8jGY/PY2d6HA4zRFBquAl0l4rEwZnrUF0EfkbaABeDEBL5NgBF5UwKwEQ/DiAv5IMAafRcA4yfWT2gAd5R8byk6+ZCz7KbCkGI1rXYCGdUtzegIsrYZGLZ4ADeuW5vQEWFoNjVo8ARrWLc3pCbC0Ghq1eAI0rFuas/oEfAN/0AhQ3IEvrwAAAABJRU5ErkJggg=='
    55. this.checkIconData = icon.replace(/[\r\n]/g, "");
    56. },
    57. computed: {
    58. },
    59. watch: {
    60. showSheetView: {
    61. handler: function(flag) {
    62. this.modalAnimation = flag
    63. this.dataList = this.optionsList
    64. },
    65. immediate: true
    66. }
    67. },
    68. methods: {
    69. cancelAction: function() {
    70. this.modalAnimation = false
    71. let self = this
    72. setTimeout(() => {
    73. // self.showSheetView = false
    74. self.$emit('onSelected', {
    75. 'cancel': true
    76. })
    77. }, 350);
    78. },
    79. okAction: function() {
    80. this.modalAnimation = false
    81. let data = this.dataList[this.selectIndex]
    82. let self = this
    83. setTimeout(() => {
    84. // self.showSheetView = false
    85. self.$emit('onSelected', {
    86. data: data,
    87. 'cancel': false,
    88. 'confirm': true
    89. })
    90. }, 350);
    91. },
    92. didSelectedRow(row) {
    93. this.selectIndex = row
    94. if (this.autoConfirm)
    95. {
    96. this.okAction()
    97. }
    98. }
    99. }
    100. }
    101. script>
    102. <style lang="scss" scoped>
    103. .scroll-view {
    104. width: 100%;
    105. height: 540upx;
    106. display: flex;
    107. flex-direction: column;
    108. justify-content: flex-start;
    109. align-items: center;
    110. }
    111. .cell-row {
    112. width: 100%;
    113. height: 88upx;
    114. border-bottom: 1px solid #eee;
    115. padding: 0upx 20upx;
    116. display: flex;
    117. flex-direction: row;
    118. justify-content: center;
    119. align-items: center;
    120. }
    121. .cell-icon {
    122. width: 40upx;
    123. height: 40upx;
    124. }
    125. .cell-check-icon
    126. {
    127. position: absolute;
    128. right: 30upx;
    129. width: 40upx;
    130. height: 40upx;
    131. }
    132. .cell-label {
    133. padding:0upx 50upx 0upx 20upx;
    134. font-size: 14px;
    135. color: #333333;
    136. display: inline-block;
    137. overflow: hidden !important;
    138. text-overflow: ellipsis !important;
    139. white-space: nowrap !important;
    140. line-clamp: 1 !important;
    141. }
    142. .cell-lb-pad
    143. {
    144. padding:0upx 50upx;
    145. }
    146. .hilight-label {
    147. color: #0286df;
    148. }
    149. .align-left {
    150. justify-content: flex-start;
    151. }
    152. .align-right {
    153. justify-content: flex-end;
    154. }
    155. .ani_start {
    156. animation: animationShow 0.4s;
    157. }
    158. .ani_end {
    159. animation: animationHide 0.4s;
    160. }
    161. @keyframes animationShow {
    162. from {
    163. background-color: rgba(0, 0, 0, 0);
    164. opacity: 0;
    165. }
    166. to {
    167. background-color: rgba(0, 0, 0, 0.2);
    168. opacity: 1;
    169. }
    170. }
    171. @keyframes animationHide {
    172. from {
    173. background-color: rgba(0, 0, 0, 0.2);
    174. opacity: 1;
    175. }
    176. to {
    177. background-color: rgba(0, 0, 0, 0);
    178. opacity: 0;
    179. }
    180. }
    181. @keyframes slideBottom {
    182. 0% {
    183. transform: translateY(100%)
    184. }
    185. 100% {
    186. transform: translateY(0)
    187. }
    188. }
    189. .view-modal {
    190. position: fixed;
    191. top: calc(var(--status-bar-height) + 44px);
    192. // bottom: 0;
    193. height: calc(100% - var(--status-bar-height) - 44px);
    194. width: 100%;
    195. z-index: 1;
    196. display: flex;
    197. flex-direction: column;
    198. justify-content: flex-start;
    199. align-items: center;
    200. background-color: rgba(0, 0, 0, 0.2);
    201. }
    202. .ani-btm {
    203. transform: translateY(640upx);
    204. }
    205. .ani-top {
    206. animation: slideBottom 0.4s;
    207. }
    208. .sheet-view {
    209. position: absolute;
    210. bottom: 0upx;
    211. height: 640upx;
    212. width: 100%;
    213. transition: all 0.25s;
    214. background-color: white;
    215. display: flex;
    216. flex-direction: column;
    217. justify-content: flex-start;
    218. align-items: center;
    219. }
    220. .head-view {
    221. position: relative;
    222. width: calc(100% - 70upx);
    223. height: 100upx;
    224. display: flex;
    225. flex-direction: row;
    226. justify-content: space-between;
    227. align-items: center;
    228. }
    229. .cancel-view {
    230. position: relative;
    231. width: 124upx;
    232. height: 100%;
    233. display: flex;
    234. flex-direction: column;
    235. justify-content: center;
    236. align-items: center;
    237. text {
    238. position: relative;
    239. width: 100%;
    240. font-size: 32upx;
    241. color: #333333;
    242. text-align: left;
    243. }
    244. }
    245. .title-view {
    246. position: relative;
    247. height: 100%;
    248. display: flex;
    249. flex-direction: column;
    250. justify-content: center;
    251. align-items: center;
    252. text {
    253. position: relative;
    254. width: 100%;
    255. font-size: 30upx;
    256. color: #999999;
    257. text-align: left;
    258. }
    259. }
    260. .ok-view {
    261. position: relative;
    262. width: 124upx;
    263. height: 100%;
    264. display: flex;
    265. flex-direction: column;
    266. justify-content: center;
    267. align-items: center;
    268. text {
    269. position: relative;
    270. width: 100%;
    271. font-size: 32upx;
    272. color: #2197FF;
    273. text-align: right;
    274. }
    275. }
    276. .mid-view {
    277. position: relative;
    278. width: 100%;
    279. height: 106upx;
    280. border-bottom: 1upx solid rgb(235, 235, 235);
    281. border-top: 1upx solid rgb(235, 235, 235);
    282. display: flex;
    283. flex-direction: row;
    284. justify-content: center;
    285. align-items: center;
    286. }
    287. .btn-view {
    288. position: relative;
    289. width: 50%;
    290. height: 100%;
    291. display: flex;
    292. flex-direction: row;
    293. justify-content: center;
    294. align-items: center;
    295. }
    296. .tt-view {
    297. position: relative;
    298. width: 100%;
    299. height: 100%;
    300. display: flex;
    301. flex-direction: column;
    302. justify-content: center;
    303. align-items: center;
    304. }
    305. .normal-text {
    306. position: relative;
    307. width: 100%;
    308. font-size: 32upx;
    309. color: #555555;
    310. text-align: center;
    311. }
    312. .hili-text {
    313. position: relative;
    314. width: 100%;
    315. font-size: 32upx;
    316. color: #2197FF;
    317. text-align: center;
    318. }
    319. .active {
    320. background-color: white;
    321. }
    322. .non-active {
    323. background-color: rgb(245, 245, 245);
    324. }
    325. style>

  • 相关阅读:
    使用 Learner Lab - 在 Lambda 建立 Pillow 层,进行 S3 的图片镜相操作
    Spring微服务无法注册到指定的Spring cloud Eureka
    零基础学Java(6)控制流程
    从0搭建Vue3组件库(十):如何搭建一个 Cli 脚手架
    Groovy之高级用法
    打开Outlook报错修复
    什么是指标体系,怎么搭建一套完整的指标体系?(附PDF素材)
    Zookeeper部署运行_服务管理
    安卓APP源码和设计报告——体育馆预约系统
    k8s KubeSphere流水线部署SpringBoot后端项目 详细教程
  • 原文地址:https://blog.csdn.net/yunhuaikong/article/details/134187470