feat: 准备各个形状的 svg 图
This commit is contained in:
@@ -7,11 +7,7 @@ Component({
|
||||
type: Number,
|
||||
value: 0,
|
||||
},
|
||||
img: {
|
||||
type: String,
|
||||
value: '',
|
||||
},
|
||||
name: {
|
||||
svg: {
|
||||
type: String,
|
||||
value: '',
|
||||
},
|
||||
@@ -20,10 +16,50 @@ Component({
|
||||
value: '',
|
||||
},
|
||||
},
|
||||
/**
|
||||
* 组件的初始数据
|
||||
*/
|
||||
data: {
|
||||
svgDataUri: '',
|
||||
},
|
||||
/**
|
||||
* 组件生命周期
|
||||
*/
|
||||
lifetimes: {
|
||||
attached() {
|
||||
this.generateSvgDataUri();
|
||||
},
|
||||
},
|
||||
/**
|
||||
* 监听属性变化
|
||||
*/
|
||||
observers: {
|
||||
'svg, color': function () {
|
||||
this.generateSvgDataUri();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 组件的方法列表
|
||||
*/
|
||||
methods: {
|
||||
/**
|
||||
* 生成完整的 SVG Data URI
|
||||
*/
|
||||
generateSvgDataUri() {
|
||||
const { svg, color } = this.data;
|
||||
if (!svg) return;
|
||||
|
||||
// 创建完整的 SVG 字符串,替换填充颜色
|
||||
const coloredSvg = svg.replace(/fill="#ff0000"/g, `fill="${color || '#ff0000'}"`);
|
||||
const completeSvg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" width="100" height="100">${coloredSvg}</svg>`;
|
||||
|
||||
// 转换为 Data URI
|
||||
const svgDataUri = `data:image/svg+xml;charset=utf-8,${encodeURIComponent(completeSvg)}`;
|
||||
|
||||
this.setData({
|
||||
svgDataUri: svgDataUri
|
||||
});
|
||||
},
|
||||
onDelete() {
|
||||
const { key } = this.data;
|
||||
this.triggerEvent('onDelete', { key });
|
||||
|
||||
Reference in New Issue
Block a user