1
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
## 1.0.1(2025-07-27)
|
||||
* 兼容原生鸿蒙
|
||||
@@ -0,0 +1,50 @@
|
||||
<template>
|
||||
<view :style="{width:_width+'px',height:_height+'px'}">
|
||||
<!-- #ifdef APP-ANDROID || APP-IOS -->
|
||||
<native-view @init="onviewinit" style="width: 100%;height: 100%;"></native-view>
|
||||
<!-- #endif -->
|
||||
<!-- #ifndef APP -->
|
||||
<img style="width: 100%;height: 100%;object-fit: contain;" :src="_src"></img>
|
||||
<!-- #endif -->
|
||||
<!-- #ifdef APP-HARMONY -->
|
||||
<image :style="{width:_width+'px',height:_height+'px'}" :src="_src"></image>
|
||||
<!-- #endif -->
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup lang="uts">
|
||||
import { xSvgU} from '@/uni_modules/x-svg-u';
|
||||
import {xSvgPropsType} from "../../utssdk/interface.uts"
|
||||
let svg : xSvgU | null = null
|
||||
let uid = 'xSvgU' + Math.random().toString(16).substring(4, 20)
|
||||
|
||||
type PropsType = {
|
||||
src:string,
|
||||
width:number,
|
||||
height:number,
|
||||
color:string
|
||||
}
|
||||
const props = withDefaults(defineProps<PropsType>(), {
|
||||
src:"",
|
||||
width:18,
|
||||
height:18,
|
||||
color:"#000000"
|
||||
})
|
||||
|
||||
const _width = computed(() : number => props.width)
|
||||
const _height = computed(() : number => props.height)
|
||||
const _src = computed(() : string => props.src)
|
||||
watch(() : Array<string | number> => [props.src, props.width, props.height, props.color], () => {
|
||||
svg?.setImage(props.src)
|
||||
})
|
||||
function onviewinit(e : UniNativeViewInitEvent) {
|
||||
svg = new xSvgU(e.detail.element);
|
||||
if(_src.value!=''){
|
||||
svg!.setImage(_src.value)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
@@ -0,0 +1,97 @@
|
||||
{
|
||||
"id": "x-svg-u",
|
||||
"displayName": "x-svg-u",
|
||||
"version": "1.0.0",
|
||||
"description": "x-svg-u",
|
||||
"keywords": [
|
||||
"x-svg-u"
|
||||
],
|
||||
"repository": "",
|
||||
"engines": {
|
||||
"HBuilderX": "^4.31",
|
||||
"uni-app": "^3.1.0",
|
||||
"uni-app-x": "^3.1.0"
|
||||
},
|
||||
"dcloudext": {
|
||||
"type": "uts-vue-component",
|
||||
"sale": {
|
||||
"regular": {
|
||||
"price": "0.00"
|
||||
},
|
||||
"sourcecode": {
|
||||
"price": "0.00"
|
||||
}
|
||||
},
|
||||
"contact": {
|
||||
"qq": ""
|
||||
},
|
||||
"declaration": {
|
||||
"ads": "",
|
||||
"data": "",
|
||||
"permissions": ""
|
||||
},
|
||||
"npmurl": "",
|
||||
"darkmode": "-",
|
||||
"i18n": "-",
|
||||
"widescreen": "-"
|
||||
},
|
||||
"uni_modules": {
|
||||
"dependencies": [],
|
||||
"encrypt": [],
|
||||
"platforms": {
|
||||
"cloud": {
|
||||
"tcb": "-",
|
||||
"aliyun": "-",
|
||||
"alipay": "-"
|
||||
},
|
||||
"client": {
|
||||
"uni-app": {
|
||||
"vue": {
|
||||
"vue2": "-",
|
||||
"vue3": "-"
|
||||
},
|
||||
"web": {
|
||||
"safari": "-",
|
||||
"chrome": "-"
|
||||
},
|
||||
"app": {
|
||||
"vue": "-",
|
||||
"nvue": "-",
|
||||
"android": "-",
|
||||
"ios": "-",
|
||||
"harmony": "-"
|
||||
},
|
||||
"mp": {
|
||||
"weixin": "-",
|
||||
"alipay": "-",
|
||||
"toutiao": "-",
|
||||
"baidu": "-",
|
||||
"kuaishou": "-",
|
||||
"jd": "-",
|
||||
"harmony": "-",
|
||||
"qq": "-",
|
||||
"lark": "-"
|
||||
},
|
||||
"quickapp": {
|
||||
"huawei": "-",
|
||||
"union": "-"
|
||||
}
|
||||
},
|
||||
"uni-app-x": {
|
||||
"web": {
|
||||
"safari": "-",
|
||||
"chrome": "-"
|
||||
},
|
||||
"app": {
|
||||
"android": "-",
|
||||
"ios": "-",
|
||||
"harmony": "-"
|
||||
},
|
||||
"mp": {
|
||||
"weixin": "-"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
# x-svg-u
|
||||
|
||||
### 开发文档
|
||||
|
||||
从 1.0.1 开始此组件变更为标准原生组件,使用时,不需要导入组件,可以直接在页面上使用组件,更方便了。
|
||||
|
||||
```vue
|
||||
<x-svg-u src="/static/undraw_farming_ni77.svg" :width="100" :height="120" ></x-svg-u>
|
||||
```
|
||||
|
||||
### 兼容性
|
||||
|
||||
| Harmony | IOS | Android | WEB | 小程序 |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| 支持 | 支持 | 支持 | 支持 | 支持 |
|
||||
|
||||
### 注意事项
|
||||
|
||||
使用前一定要打基座才可用,一定要在页面上先引用,再去打基座。
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"minSdkVersion": "21",
|
||||
"dependencies":[
|
||||
"com.caverock:androidsvg:1.4"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import View from "android.view.View";
|
||||
import InputStream from "java.io.InputStream";
|
||||
import Context from "com.alibaba.fastjson.parser.deserializer.ASMDeserializerFactory.Context";
|
||||
import FileInputStream from "java.io.FileInputStream";
|
||||
import File from "java.io.File";
|
||||
import PictureDrawable from "android.graphics.drawable.PictureDrawable";
|
||||
import SVG from "com.caverock.androidsvg.SVG"
|
||||
import ImageView from 'android.widget.ImageView';
|
||||
|
||||
export class xSvgU {
|
||||
$element : UniNativeViewElement;
|
||||
targetView : ImageView | null = null;
|
||||
constructor(element : UniNativeViewElement) {
|
||||
//接收传递过来的UniNativeViewElement
|
||||
this.$element = element;
|
||||
this.bindView();
|
||||
}
|
||||
bindView() {
|
||||
this.targetView = new ImageView(this.$element.getAndroidActivity()!); //构建原生view
|
||||
this.$element.bindAndroidView(this.targetView!);
|
||||
}
|
||||
setImage(newval:string){
|
||||
let furl = UTSAndroid.convert2AbsFullPath(newval)
|
||||
let inputStream:InputStream|null = null;
|
||||
if(furl.indexOf('android_asset')==-1){
|
||||
inputStream = new FileInputStream(new File(furl))
|
||||
}else{
|
||||
inputStream = UTSAndroid.getUniActivity()!.getAssets().open(furl.replace("/android_asset/", ""));
|
||||
}
|
||||
if(inputStream ==null) return
|
||||
let svg = SVG.getFromInputStream(inputStream!);
|
||||
let pictureDrawable = new PictureDrawable(svg.renderToPicture());
|
||||
this.targetView?.setImageDrawable(pictureDrawable);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class xSvgU {}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"deploymentTarget": "12",
|
||||
"dependencies-pods": [{
|
||||
"name": "SVGKit",
|
||||
"version": "3.0.0"
|
||||
}]
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
import {
|
||||
UIButton,
|
||||
UIControl,
|
||||
UIImageView,
|
||||
UIImage
|
||||
} from "UIKit"
|
||||
import { SVGKImage } from "SVGKit" assert { type: "implementationOnly" };
|
||||
import { UTSComponent } from "DCloudUTSFoundation"
|
||||
import { Data } from 'Assignables';
|
||||
import { CALayer } from 'QuartzCore';
|
||||
import { CGRect, CGSize } from 'CoreFoundation';
|
||||
|
||||
|
||||
|
||||
export class xSvgU {
|
||||
$element : UniNativeViewElement;
|
||||
targetView : UIImageView | null = null;
|
||||
constructor(element : UniNativeViewElement) {
|
||||
this.$element = element;
|
||||
this.targetView = new UIImageView()
|
||||
this.$element.bindIOSView(this.targetView!);
|
||||
}
|
||||
|
||||
setImage(newval : string) {
|
||||
if (newval != '') {
|
||||
let url = UTSiOS.getResourcePath(newval)
|
||||
// let width = (16).toInt();
|
||||
// let height = (16).toInt();
|
||||
// this.targetView!.frame = new CGRect(x = 0, y = 0, width = width, height = height);
|
||||
const size:CGRect = this.targetView!.frame;
|
||||
let svgURL = new URL(fileURLWithPath = url)
|
||||
let svgData = UTSiOS.try(new Data(contentsOf = svgURL),"?")
|
||||
if(svgData==null) return;
|
||||
let svgImage = new SVGKImage(data = svgData!)
|
||||
svgImage!.size = new CGSize(width= size.width, height= size.height)
|
||||
this.targetView!.image = svgImage?.uiImage
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export type xSvgPropsType = {
|
||||
src:string,
|
||||
width:number,
|
||||
height:number,
|
||||
color:string
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export class xSvgU {}
|
||||
@@ -0,0 +1 @@
|
||||
export class xSvgU {}
|
||||
Reference in New Issue
Block a user