feat(P4): precompute移植+app.js sources双向回填+回归1003/1003+验收体积/文件/data.json
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Aurora Admin · ButtonGroup(普通 H5)</title>
|
||||
<link rel="stylesheet" href="../.design_library/aurora-admin/colors_and_type.css" />
|
||||
<link rel="stylesheet" href="ButtonGroup.css" />
|
||||
<style>body{margin:0;padding:24px;background: var(--au-color-page-bg);display:flex;flex-direction:column;gap:16px;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="aa-btngroup" id="single"></div>
|
||||
<div class="aa-btngroup" id="multi"></div>
|
||||
|
||||
<script>
|
||||
function paint(el, options, selected, multiple) {
|
||||
el.innerHTML = options.map(function (o) {
|
||||
var on = multiple ? selected.indexOf(o.value) >= 0 : selected === o.value;
|
||||
var cls = 'aa-btngroup-btn' + (on ? ' is-selected' : '') + (o.disabled ? ' is-disabled' : '');
|
||||
return '<button class="' + cls + '" data-value="' + o.value + '" ' + (o.disabled ? 'disabled' : '') + '>' + o.label + '</button>';
|
||||
}).join('');
|
||||
el.querySelectorAll('button').forEach(function (b) {
|
||||
b.addEventListener('click', function () {
|
||||
var v = b.dataset.value;
|
||||
if (multiple) {
|
||||
var i = selected.indexOf(v);
|
||||
if (i >= 0) selected.splice(i, 1); else selected.push(v);
|
||||
} else {
|
||||
selected = v;
|
||||
}
|
||||
paint(el, options, selected, multiple);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
paint(document.getElementById('single'),
|
||||
[{ label: '日', value: 'day' }, { label: '周', value: 'week' }, { label: '月', value: 'month' }], 'week', false);
|
||||
|
||||
paint(document.getElementById('multi'),
|
||||
[{ label: '红', value: 'r' }, { label: '绿', value: 'g' }, { label: '蓝', value: 'b', disabled: true }], ['r'], true);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,37 @@
|
||||
import React from 'react';
|
||||
import './ButtonGroup.css';
|
||||
|
||||
export default function ButtonGroup({ options = [], value, multiple = false, size = 'default', onChange }) {
|
||||
function isSelected(v) {
|
||||
return multiple ? (value || []).indexOf(v) >= 0 : value === v;
|
||||
}
|
||||
function toggle(o) {
|
||||
if (o.disabled) return;
|
||||
let next;
|
||||
if (multiple) {
|
||||
const arr = (value || []).slice();
|
||||
const idx = arr.indexOf(o.value);
|
||||
if (idx >= 0) arr.splice(idx, 1); else arr.push(o.value);
|
||||
next = arr;
|
||||
} else {
|
||||
next = o.value;
|
||||
}
|
||||
onChange && onChange(next);
|
||||
}
|
||||
|
||||
const sizeCls = size === 'small' ? ' is-sm' : size === 'large' ? ' is-lg' : '';
|
||||
return (
|
||||
<div className={'aa-btngroup' + sizeCls}>
|
||||
{options.map((o, i) => (
|
||||
<button
|
||||
key={i}
|
||||
className={'aa-btngroup-btn' + (isSelected(o.value) ? ' is-selected' : '') + (o.disabled ? ' is-disabled' : '')}
|
||||
disabled={!!o.disabled}
|
||||
onClick={() => toggle(o)}
|
||||
>
|
||||
{o.label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<template>
|
||||
<div class="aa-btngroup" :class="{ 'is-sm': size === 'small', 'is-lg': size === 'large' }">
|
||||
<button v-for="(o, i) in options" :key="i"
|
||||
class="aa-btngroup-btn"
|
||||
:class="{ 'is-selected': isSelected(o.value), 'is-disabled': !!o.disabled }"
|
||||
:disabled="!!o.disabled"
|
||||
@click="toggle(o)">
|
||||
{{ o.label }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'AaButtonGroup',
|
||||
props: {
|
||||
options: { type: Array, default: function () { return []; } },
|
||||
value: { type: [String, Array], default: '' },
|
||||
multiple: { type: Boolean, default: false },
|
||||
size: { type: String, default: 'default' }
|
||||
},
|
||||
methods: {
|
||||
isSelected: function (v) {
|
||||
return this.multiple ? this.value.indexOf(v) >= 0 : this.value === v;
|
||||
},
|
||||
toggle: function (o) {
|
||||
if (o.disabled) return;
|
||||
var next;
|
||||
if (this.multiple) {
|
||||
var arr = (this.value || []).slice();
|
||||
var idx = arr.indexOf(o.value);
|
||||
if (idx >= 0) arr.splice(idx, 1); else arr.push(o.value);
|
||||
next = arr;
|
||||
} else {
|
||||
next = o.value;
|
||||
}
|
||||
this.$emit('input', next);
|
||||
this.$emit('change', next);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style src="./ButtonGroup.css"></style>
|
||||
@@ -0,0 +1,41 @@
|
||||
<template>
|
||||
<div class="aa-btngroup" :class="{ 'is-sm': size === 'small', 'is-lg': size === 'large' }">
|
||||
<button v-for="(o, i) in options" :key="i"
|
||||
class="aa-btngroup-btn"
|
||||
:class="{ 'is-selected': isSelected(o.value), 'is-disabled': !!o.disabled }"
|
||||
:disabled="!!o.disabled"
|
||||
@click="toggle(o)">
|
||||
{{ o.label }}
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
const props = defineProps({
|
||||
options: { type: Array, default: () => [] },
|
||||
modelValue: { type: [String, Array], default: '' },
|
||||
multiple: { type: Boolean, default: false },
|
||||
size: { type: String, default: 'default' }
|
||||
});
|
||||
const emit = defineEmits(['update:modelValue', 'change']);
|
||||
|
||||
function isSelected(v) {
|
||||
return props.multiple ? props.modelValue.indexOf(v) >= 0 : props.modelValue === v;
|
||||
}
|
||||
function toggle(o) {
|
||||
if (o.disabled) return;
|
||||
let next;
|
||||
if (props.multiple) {
|
||||
const arr = (props.modelValue || []).slice();
|
||||
const idx = arr.indexOf(o.value);
|
||||
if (idx >= 0) arr.splice(idx, 1); else arr.push(o.value);
|
||||
next = arr;
|
||||
} else {
|
||||
next = o.value;
|
||||
}
|
||||
emit('update:modelValue', next);
|
||||
emit('change', next);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style src="./ButtonGroup.css"></style>
|
||||
Reference in New Issue
Block a user