feat(P4): precompute移植+app.js sources双向回填+回归1003/1003+验收体积/文件/data.json
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<!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 · SwitchGroup(普通 H5)</title>
|
||||
<link rel="stylesheet" href="../.design_library/aurora-admin/colors_and_type.css" />
|
||||
<link rel="stylesheet" href="SwitchGroup.css" />
|
||||
<style>body{margin:0;padding:24px;background: var(--au-color-page-bg);} .aa-panel{background: var(--au-color-card-bg);border: 1px solid var(--au-color-border);border-radius:8px;padding:16px;max-width:360px;}</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="aa-panel">
|
||||
<div class="aa-switchgroup" role="group" id="app"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var DATA = [
|
||||
{ label: '邮件通知', value: 'mail', desc: '接收系统邮件提醒', on: true },
|
||||
{ label: '短信通知', value: 'sms', desc: '重要变更发送短信', on: false },
|
||||
{ label: '站内信', value: 'inbox', desc: '工作台消息中心', on: true }
|
||||
];
|
||||
|
||||
function render() {
|
||||
var root = document.getElementById('app');
|
||||
var allOn = DATA.every(function (d) { return d.on; });
|
||||
var html = '<div class="aa-switchgroup-head" role="group"><span class="aa-switchgroup-title">通知设置</span>' +
|
||||
'<div class="aa-switch ' + (allOn ? 'is-on' : '') + '" role="switch" tabindex="0" aria-checked="false" data-all="1"></div></div>';
|
||||
html += DATA.map(function (d) {
|
||||
return '<div class="aa-switch-row" role="switch" tabindex="0" aria-checked="false"><div class="aa-switch-text" aria-checked="false">' +
|
||||
'<span class="aa-switch-label" aria-checked="false">' + d.label + '</span>' +
|
||||
'<span class="aa-switch-desc" aria-checked="false">' + d.desc + '</span></div>' +
|
||||
'<div class="aa-switch ' + (d.on ? 'is-on' : '') + '" role="switch" tabindex="0" aria-checked="false" data-value="' + d.value + '"></div></div>';
|
||||
}).join('');
|
||||
root.innerHTML = html;
|
||||
|
||||
root.querySelector('[data-all]').addEventListener('click', function () {
|
||||
var target = !DATA.every(function (d) { return d.on; });
|
||||
DATA.forEach(function (d) { d.on = target; });
|
||||
render();
|
||||
});
|
||||
root.querySelectorAll('[data-value]').forEach(function (el) {
|
||||
el.addEventListener('click', function () {
|
||||
var v = el.dataset.value;
|
||||
DATA.forEach(function (d) { if (d.value === v) d.on = !d.on; });
|
||||
render();
|
||||
});
|
||||
});
|
||||
}
|
||||
render();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,41 @@
|
||||
import React, { useState } from 'react';
|
||||
import './SwitchGroup.css';
|
||||
|
||||
export default function SwitchGroup({ options = [], value = [], title = '', selectAll = false, onChange }) {
|
||||
const allOn = options.length > 0 && options.every(o => value.indexOf(o.value) >= 0);
|
||||
|
||||
function toggle(v) {
|
||||
const arr = value.slice();
|
||||
const idx = arr.indexOf(v);
|
||||
if (idx >= 0) arr.splice(idx, 1); else arr.push(v);
|
||||
onChange && onChange(arr);
|
||||
}
|
||||
function toggleAll() {
|
||||
onChange && onChange(allOn ? [] : options.map(o => o.value));
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="aa-switchgroup">
|
||||
{(title || selectAll) ? (
|
||||
<div className="aa-switchgroup-head">
|
||||
<span className="aa-switchgroup-title">{title}</span>
|
||||
{selectAll ? (
|
||||
<div className={'aa-switch' + (allOn ? ' is-on' : '')} onClick={toggleAll} />
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
{options.map((o, i) => (
|
||||
<div className="aa-switch-row" key={i}>
|
||||
<div className="aa-switch-text">
|
||||
<span className="aa-switch-label">{o.label}</span>
|
||||
{o.desc ? <span className="aa-switch-desc">{o.desc}</span> : null}
|
||||
</div>
|
||||
<div
|
||||
className={'aa-switch' + (value.indexOf(o.value) >= 0 ? ' is-on' : '')}
|
||||
onClick={() => toggle(o.value)}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<template>
|
||||
<div class="aa-switchgroup">
|
||||
<div class="aa-switchgroup-head" v-if="title || selectAll">
|
||||
<span class="aa-switchgroup-title">{{ title }}</span>
|
||||
<div v-if="selectAll" class="aa-switch" :class="{ 'is-on': allOn }" @click="toggleAll"></div>
|
||||
</div>
|
||||
<div class="aa-switch-row" v-for="(o, i) in options" :key="i">
|
||||
<div class="aa-switch-text">
|
||||
<span class="aa-switch-label">{{ o.label }}</span>
|
||||
<span class="aa-switch-desc" v-if="o.desc">{{ o.desc }}</span>
|
||||
</div>
|
||||
<div class="aa-switch" :class="{ 'is-on': value.indexOf(o.value) >= 0 }" @click="toggle(o.value)"></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'AaSwitchGroup',
|
||||
props: {
|
||||
options: { type: Array, default: function () { return []; } },
|
||||
value: { type: Array, default: function () { return []; } },
|
||||
title: { type: String, default: '' },
|
||||
selectAll: { type: Boolean, default: false }
|
||||
},
|
||||
computed: {
|
||||
allOn: function () {
|
||||
return this.options.length > 0 && this.options.every(function (o) { return this.value.indexOf(o.value) >= 0; }, this);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
toggle: function (v) {
|
||||
var arr = this.value.slice();
|
||||
var idx = arr.indexOf(v);
|
||||
if (idx >= 0) arr.splice(idx, 1); else arr.push(v);
|
||||
this.$emit('input', arr);
|
||||
},
|
||||
toggleAll: function () {
|
||||
var next = this.allOn ? [] : this.options.map(function (o) { return o.value; });
|
||||
this.$emit('input', next);
|
||||
}
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style src="./SwitchGroup.css"></style>
|
||||
@@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<div class="aa-switchgroup">
|
||||
<div class="aa-switchgroup-head" v-if="title || selectAll">
|
||||
<span class="aa-switchgroup-title">{{ title }}</span>
|
||||
<div v-if="selectAll" class="aa-switch" :class="{ 'is-on': allOn }" @click="toggleAll"></div>
|
||||
</div>
|
||||
<div class="aa-switch-row" v-for="(o, i) in options" :key="i">
|
||||
<div class="aa-switch-text">
|
||||
<span class="aa-switch-label">{{ o.label }}</span>
|
||||
<span class="aa-switch-desc" v-if="o.desc">{{ o.desc }}</span>
|
||||
</div>
|
||||
<div class="aa-switch" :class="{ 'is-on': modelValue.indexOf(o.value) >= 0 }" @click="toggle(o.value)"></div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed } from 'vue';
|
||||
const props = defineProps({
|
||||
options: { type: Array, default: () => [] },
|
||||
modelValue: { type: Array, default: () => [] },
|
||||
title: { type: String, default: '' },
|
||||
selectAll: { type: Boolean, default: false }
|
||||
});
|
||||
const emit = defineEmits(['update:modelValue']);
|
||||
|
||||
const allOn = computed(() =>
|
||||
props.options.length > 0 && props.options.every(o => props.modelValue.indexOf(o.value) >= 0)
|
||||
);
|
||||
|
||||
function toggle(v) {
|
||||
const arr = props.modelValue.slice();
|
||||
const idx = arr.indexOf(v);
|
||||
if (idx >= 0) arr.splice(idx, 1); else arr.push(v);
|
||||
emit('update:modelValue', arr);
|
||||
}
|
||||
function toggleAll() {
|
||||
const next = allOn.value ? [] : props.options.map(o => o.value);
|
||||
emit('update:modelValue', next);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style src="./SwitchGroup.css"></style>
|
||||
Reference in New Issue
Block a user