合同小程序前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
3.1 KiB

3 months ago
  1. <template>
  2. <view class="defaultStyles">
  3. </view>
  4. </template>
  5. <script lang="uts">
  6. /**
  7. * 引用 iOS 系统库
  8. * [可选实现按需引入]
  9. */
  10. import { UIImage, UIView, UIImageView } from "UIKit"
  11. import { setSvgImage } from './utils'
  12. //原生提供以下属性或方法的实现
  13. export default {
  14. data() {
  15. return {};
  16. },
  17. /**
  18. * 组件名称也就是开发者使用的标签
  19. */
  20. name: "l-svg-x",
  21. /**
  22. * 组件涉及的事件声明只有声明过的事件才能被正常发送
  23. */
  24. emits: ['click'],
  25. /**
  26. * 属性声明组件的使用者会传递这些属性值到组件
  27. */
  28. props: {
  29. "src": {
  30. type: String,
  31. default: ""
  32. },
  33. "color": {
  34. type: String,
  35. default: ""
  36. }
  37. },
  38. /**
  39. * 组件内部变量声明
  40. */
  41. /**
  42. * 属性变化监听器实现
  43. */
  44. watch: {
  45. "src": {
  46. handler(newValue : String, oldValue : String) {
  47. this.update(true)
  48. },
  49. immediate: false
  50. },
  51. "color": {
  52. /**
  53. * 这里监听属性变化并进行组件内部更新
  54. */
  55. handler(newValue : String, oldValue : String) {
  56. if (this.color == '') return
  57. this.update(false)
  58. },
  59. immediate: false
  60. },
  61. },
  62. /**
  63. * 规则如果没有配置expose则methods中的方法均对外暴露如果配置了expose则以expose的配置为准向外暴露
  64. * ['publicMethod'] 含义为只有 `publicMethod` 在实例上可用
  65. */
  66. // expose: [],
  67. methods: {
  68. update(flag : boolean) {
  69. setSvgImage(this.src, this.color, (image: UIImage|null)=>{
  70. if(image != null){
  71. this.$el.image = image
  72. if(flag){
  73. this.$emit('load')
  74. }
  75. return
  76. }
  77. this.$emit('error')
  78. })
  79. }
  80. },
  81. /**
  82. * 组件被创建组件第一个生命周期
  83. * 在内存中被占用的时候被调用开发者可以在这里执行一些需要提前执行的初始化逻辑
  84. * [可选实现]
  85. */
  86. created() {
  87. },
  88. /**
  89. * 对应平台的view载体即将被创建对应前端beforeMount
  90. * [可选实现]
  91. */
  92. NVBeforeLoad() {
  93. },
  94. /**
  95. * 创建原生View必须定义返回值类型
  96. * 开发者需要重点实现这个函数声明原生组件被创建出来的过程以及最终生成的原生组件类型
  97. * [必须实现]
  98. */
  99. NVLoad() : UIImageView {
  100. let imageView = new UIImageView()
  101. imageView.contentMode = UIView.ContentMode.scaleAspectFit
  102. imageView.isUserInteractionEnabled = true
  103. return imageView
  104. },
  105. /**
  106. * 原生View已创建
  107. * [可选实现]
  108. */
  109. NVLoaded() {
  110. /**
  111. * 通过 this.$el 来获取原生控件
  112. */
  113. this.update(true)
  114. },
  115. /**
  116. * 原生View布局完成
  117. * [可选实现]
  118. */
  119. NVLayouted() {
  120. },
  121. /**
  122. * 原生View将释放
  123. * [可选实现]
  124. */
  125. NVBeforeUnload() { },
  126. /**
  127. * 原生View已释放这里可以做释放View之后的操作
  128. * [可选实现]
  129. */
  130. NVUnloaded() {
  131. },
  132. /**
  133. * 组件销毁
  134. * [可选实现]
  135. */
  136. unmounted() { }
  137. /**
  138. * 更多组件开发的信息详见https://uniapp.dcloud.net.cn/plugin/uts-component.html
  139. */
  140. }
  141. </script>
  142. <style>
  143. </style>