Commit b3623798 authored by sliao's avatar sliao

fix

parent a4a3ee8e
...@@ -14,10 +14,8 @@ ...@@ -14,10 +14,8 @@
}, },
"dependencies": { "dependencies": {
"@ray-js/build-plugin-router": "^0.6.15", "@ray-js/build-plugin-router": "^0.6.15",
"@ray-js/panel-sdk": "^1.1.3", "@ray-js/panel-sdk": "^1.2.1",
"@ray-js/ray": "^0.6.13", "@ray-js/ray": "^0.6.13",
"@ray-js/sdm-react": "^1.0.6",
"@tuya-miniapp/sdm": "^1.1.0-beta.0",
"ahooks": "^3.7.1", "ahooks": "^3.7.1",
"clsx": "^1.2.1", "clsx": "^1.2.1",
"dayjs": "^1.11.5", "dayjs": "^1.11.5",
......
import React from 'react'; import React from 'react';
import { kit } from '@ray-js/panel-sdk'; import { kit, SdmProvider } from '@ray-js/panel-sdk';
import 'ray'; import 'ray';
import '@/i18n'; import '@/i18n';
import composeLayout from './composeLayout'; import composeLayout from './composeLayout';
import { SdmProvider } from '@ray-js/sdm-react'; // import { } from '@ray-js/sdm-react';
import { devices } from '@/devices'; import { devices } from '@/devices';
// import { ProductName } from '@/constants'; // import { ProductName } from '@/constants';
......
import React from 'react'; import React from 'react';
import { DpBooleanAction, DpCommonAction } from '@tuya-miniapp/sdm'; import { DpBooleanAction, DpCommonAction } from '@ray-js/panel-sdk';
import { useSdmProps } from '@ray-js/sdm-react'; import { useSdmProps } from '@ray-js/panel-sdk';
import { devices } from '@/devices'; import { devices } from '@/devices';
import styles from '../../pages/home/index.module.less'; import styles from '../../pages/home/index.module.less';
import { Image, View, Text } from '@ray-js/components'; import { Image, View, Text } from '@ray-js/components';
...@@ -84,7 +84,7 @@ export const FanVertical = React.memo(() => { ...@@ -84,7 +84,7 @@ export const FanVertical = React.memo(() => {
} }
const clickNum = (val, index) => { const clickNum = (val, index) => {
console.log(val, index); console.log(val, index, 'clickNummmm');
if (index == 0 && fanVerticalSwitch) { if (index == 0 && fanVerticalSwitch) {
fanVerticalAction.set(String(val)); fanVerticalAction.set(String(val));
} else if (index == 1 && fanHorizontalSwitch) { } else if (index == 1 && fanHorizontalSwitch) {
......
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import clsx from 'clsx'; // import clsx from 'clsx';
// import { View } from '@ray-js/ray'; // import { View } from '@ray-js/ray';
import { DpBooleanAction, DpCommonAction } from '@tuya-miniapp/sdm'; import { DpBooleanAction, DpCommonAction } from '@ray-js/panel-sdk';
import { useSdmProps } from '@ray-js/sdm-react'; import { useSdmProps } from '@ray-js/panel-sdk';
import { devices } from '@/devices'; import { devices } from '@/devices';
import styles from './index.module.less'; import styles from './index.module.less';
import { Image, View } from '@ray-js/components'; import { Image, View } from '@ray-js/components';
import iconClose from '../../../public/icon-close.png'; import iconClose from '../../../public/icon-close.png';
import iconLightWhite from '../../../public/icon-light-white.png'; import iconLightWhite from '../../../public/icon-light-white.png';
import iconSun from '../../../public/icon-sun.png'; import iconSun from '../../../public/icon-sun.png';
import { usePageEvent } from '@ray-js/ray'; // import { usePageEvent } from '@ray-js/ray';
export interface Props { export interface Props {
isShow: boolean; isShow: boolean;
setModal: (boolean) => void; setModal: (boolean) => void;
...@@ -29,10 +29,11 @@ export const LightPanel = React.memo<Props>(props => { ...@@ -29,10 +29,11 @@ export const LightPanel = React.memo<Props>(props => {
const percent = getValueInRange(val || 10, brightRange).percent; const percent = getValueInRange(val || 10, brightRange).percent;
return percent; return percent;
}); });
const temperatureVal = useSdmProps(dpState => { const temperatureVal = useSdmProps(dpState => {
const val = dpState[temperatureCode]; const val = dpState[temperatureCode];
// const percent = getValueInRange(val || 0, cctRange).percent const originX = getOrignPointX(val);
return val; return originX;
}); });
const switchVal = useSdmProps(dpState => dpState[switchCode]); const switchVal = useSdmProps(dpState => dpState[switchCode]);
...@@ -42,14 +43,25 @@ export const LightPanel = React.memo<Props>(props => { ...@@ -42,14 +43,25 @@ export const LightPanel = React.memo<Props>(props => {
const brightAction = actions[brightCode] as DpCommonAction<number>; const brightAction = actions[brightCode] as DpCommonAction<number>;
const temperatureAction = actions[temperatureCode] as DpCommonAction<number>; const temperatureAction = actions[temperatureCode] as DpCommonAction<number>;
const [point, setPoint] = useState({ pageX: 0, pageY: 250 }); const [point, setPoint] = useState({ pageX: temperatureVal, pageY: 250 });
// const [selectColor, setColor] = useState(pointToRGB(point.pageX));
const [brightPercent, setBrightPercent] = useState(brightVal); const [brightPercent, setBrightPercent] = useState(brightVal);
function getOrignPointX() { useEffect(() => {
const percent = getValueInRange(temperatureVal || 10, cctRange).percent; if (brightVal !== brightPercent) {
setBrightPercent(brightVal);
}
}, [brightVal]);
// useEffect(() => {
// if (temperatureVal !== point.pageX) {
// setPoint({ pageX: temperatureVal, pageY: 250 })
// }
// }, [temperatureVal])
function getOrignPointX(val = temperatureVal) {
const percent = getValueInRange(val || 10, cctRange).percent;
const originX = 28 + 319 * (percent / 100); const originX = 28 + 319 * (percent / 100);
console.log(temperatureVal, percent, originX); console.log(val, percent, originX);
return originX; return originX;
} }
//0-value是值 1-value是百分比 左边最小值是0,右边最大值range[1],起始位置rang[0] //0-value是值 1-value是百分比 左边最小值是0,右边最大值range[1],起始位置rang[0]
...@@ -61,16 +73,11 @@ export const LightPanel = React.memo<Props>(props => { ...@@ -61,16 +73,11 @@ export const LightPanel = React.memo<Props>(props => {
}; };
} }
usePageEvent('onShow', () => {
setPoint({
pageX: getOrignPointX(),
pageY: 250,
});
});
function touchStart(e) { function touchStart(e) {
// e.origin.stopPropagation(); // e.origin.stopPropagation();
handlePoint(e); // handlePoint(e);
} }
function handleTouch(e) { function handleTouch(e) {
...@@ -79,6 +86,7 @@ export const LightPanel = React.memo<Props>(props => { ...@@ -79,6 +86,7 @@ export const LightPanel = React.memo<Props>(props => {
} }
function touchEnd(e) { function touchEnd(e) {
console.log(e, 'touchEnd');
handlePoint(e); handlePoint(e);
} }
...@@ -100,8 +108,8 @@ export const LightPanel = React.memo<Props>(props => { ...@@ -100,8 +108,8 @@ export const LightPanel = React.memo<Props>(props => {
y = 320; y = 320;
} }
// console.log(x, 'xxxxxxx');
setPoint({ pageX: x, pageY: y }); setPoint({ pageX: x, pageY: y });
console.log(x, y, 'xxxxxxyyyyyyyy');
const percent = (x - xRange[0]) / (xRange[1] - xRange[0]); const percent = (x - xRange[0]) / (xRange[1] - xRange[0]);
const value = Number((cctRange[1] * percent).toFixed()); const value = Number((cctRange[1] * percent).toFixed());
// setColor(pointToRGB(x)); // setColor(pointToRGB(x));
...@@ -156,8 +164,9 @@ export const LightPanel = React.memo<Props>(props => { ...@@ -156,8 +164,9 @@ export const LightPanel = React.memo<Props>(props => {
} }
function progressEnd(e) { function progressEnd(e) {
// console.log(e, 'progressEnd'); console.log(e, 'progressEnd');
handleProgress(e); handleProgress(e);
} }
function handleProgress(e, isAction = true) { function handleProgress(e, isAction = true) {
...@@ -172,6 +181,7 @@ export const LightPanel = React.memo<Props>(props => { ...@@ -172,6 +181,7 @@ export const LightPanel = React.memo<Props>(props => {
const percent = differ / (xRange[1] - xRange[0]); const percent = differ / (xRange[1] - xRange[0]);
const value = Number((brightRange[1] * percent).toFixed()); const value = Number((brightRange[1] * percent).toFixed());
setBrightPercent(Number((percent * 100).toFixed())); setBrightPercent(Number((percent * 100).toFixed()));
console.log(brightPercent, 'brightPercent brightPercent');
if (isAction) { if (isAction) {
brightAction.set(value); brightAction.set(value);
} }
......
import { SmartDeviceModel } from '@tuya-miniapp/sdm'; import { SmartDeviceModel } from '@ray-js/panel-sdk';
// import { ProductName } from '@/constants';
type SmartDeviceSchema = typeof import('@/devices/schema').fanSchema;
// type SmartDevices = {
// [ProductName]?: import('@tuya-miniapp/sdm').SmartDeviceModel<SmartDeviceSchema>;
// };
export const devices = { export const devices = {
fan: new SmartDeviceModel<SmartDeviceSchema>(), fan: new SmartDeviceModel<typeof import('@/devices/schema').fanSchema>(),
}; };
Object.keys(devices).forEach((k: keyof typeof devices) => { Object.keys(devices).forEach((k: keyof typeof devices) => {
devices[k].init(); devices[k].init();
}); });
...@@ -46,9 +46,9 @@ import modeOn from '../../../public/icon-mode-on.png'; ...@@ -46,9 +46,9 @@ import modeOn from '../../../public/icon-mode-on.png';
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { LightPanel, FanVertical } from '@/components'; import { LightPanel, FanVertical } from '@/components';
import { useSdmProps, useSdmDevice } from '@ray-js/sdm-react'; import { useSdmProps, useSdmDevice } from '@ray-js/panel-sdk';
import { devices } from '@/devices'; import { devices } from '@/devices';
import { DpBooleanAction, DpCommonAction } from '@tuya-miniapp/sdm'; import { DpBooleanAction, DpCommonAction } from '@ray-js/panel-sdk';
export function Home() { export function Home() {
const deviceName = useSdmDevice(d => d.devInfo.name); const deviceName = useSdmDevice(d => d.devInfo.name);
...@@ -64,7 +64,15 @@ export function Home() { ...@@ -64,7 +64,15 @@ export function Home() {
const isOpen = useSdmProps(props => { const isOpen = useSdmProps(props => {
return Boolean(props[fanSwitchCode]); return Boolean(props[fanSwitchCode]);
}); });
const fanSpeedVal = useSdmProps(props => Number(props[fanSpeedCode])); const fanSpeedVal = useSdmProps(props => {
return Number(props[fanSpeedCode])
});
const [sliderValue, setSliderValue] = useState(fanSpeedVal);
useEffect(() => {
if (fanSpeedVal !== sliderValue) {
setSliderValue(fanSpeedVal)
}
}, [fanSpeedVal])
const fanModeVal = useSdmProps(props => props[fanModeCode]); const fanModeVal = useSdmProps(props => props[fanModeCode]);
const currentTempVal = useSdmProps(props => props[currentTempCode]); const currentTempVal = useSdmProps(props => props[currentTempCode]);
...@@ -75,13 +83,7 @@ export function Home() { ...@@ -75,13 +83,7 @@ export function Home() {
const speedAction = actions[fanSpeedCode] as DpCommonAction<number>; const speedAction = actions[fanSpeedCode] as DpCommonAction<number>;
const fanModeAction = actions[fanModeCode] as DpCommonAction<string>; const fanModeAction = actions[fanModeCode] as DpCommonAction<string>;
const [sliderValue, setSliderValue] = useState(1);
usePageEvent('onShow', () => {
console.log('home on show');
const val = fanSpeedVal;
setSliderValue(val);
});
const menu = [ const menu = [
{ {
...@@ -253,7 +255,6 @@ export function Home() { ...@@ -253,7 +255,6 @@ export function Home() {
step={5} step={5}
disabled={!isOpen} disabled={!isOpen}
onChange={e => { onChange={e => {
setSliderValue(e.value);
speedAction.set(e.value); speedAction.set(e.value);
}} }}
onChanging={e => { onChanging={e => {
......
import { ProductName } from '@/constants';
type SmartDeviceSchema = typeof import('@/devices/schema').fanSchema; type SmartDeviceSchema = typeof import('@/devices/schema').fanSchema;
type SmartDevices = { type SmartDevices = {
fan?: import('@tuya-miniapp/sdm').SmartDeviceModel<SmartDeviceSchema>; /**
* 此处 TS 类型定义建议以智能设备的名称作为键名赋值
*/
fan?: import('@ray-js/panel-sdk').SmartDeviceModel<SmartDeviceSchema>;
}; };
// declare module '@ray-js/sdm-react' { declare module '@ray-js/panel-sdk' {
// export const SdmProvider: React.FC<{ export const SdmProvider: React.FC<{
// value: SmartDeviceModel<SmartDeviceSchema>; value: SmartDeviceModel<SmartDeviceSchema>;
// children: React.ReactNode; children: React.ReactNode;
// }>; }>;
// export type SmartDeviceInstanceData = { export type SmartDeviceInstanceData = {
// devInfo: ReturnType<SmartDevices[ProductName]['getDevInfo']>; devInfo: ReturnType<SmartDevices['fan']['getDevInfo']>;
// dpSchema: ReturnType<SmartDevices[ProductName]['getDpSchema']>; dpSchema: ReturnType<SmartDevices['fan']['getDpSchema']>;
// network: ReturnType<SmartDevices[ProductName]['getNetwork']>; network: ReturnType<SmartDevices['fan']['getNetwork']>;
// bluetooth: ReturnType<SmartDevices[ProductName]['getBluetooth']>; bluetooth: ReturnType<SmartDevices['fan']['getBluetooth']>;
// }; };
// export function useProps(): SmartDevices[ProductName]['model']['props']; export function useSdmProps(): SmartDevices['fan']['model']['props'];
// export function useProps<Value extends any>( export function useSdmProps<Value extends any>(
// selector: (props?: SmartDevices[ProductName]['model']['props']) => Value, selector: (props?: SmartDevices['fan']['model']['props']) => Value,
// equalityFn?: (a: Value, b: Value) => boolean equalityFn?: (a: Value, b: Value) => boolean,
// ): Value; ): Value;
// export function useDevice(): SmartDeviceInstanceData; export function useSdmDevice(): SmartDeviceInstanceData;
// export function useDevice<Device extends any>( export function useSdmDevice<Device extends any>(
// selector: (device: SmartDeviceInstanceData) => Device, selector: (device: SmartDeviceInstanceData) => Device,
// equalityFn?: (a: Device, b: Device) => boolean equalityFn?: (a: Device, b: Device) => boolean,
// ): Device; ): Device;
// export function useActions(): SmartDevices[ProductName]['model']['actions']; }
// } \ No newline at end of file
...@@ -2035,19 +2035,28 @@ ...@@ -2035,19 +2035,28 @@
"@ray-js/router" "^0.6.15" "@ray-js/router" "^0.6.15"
"@ray-js/router-mp" "^0.6.15" "@ray-js/router-mp" "^0.6.15"
"@ray-js/panel-base-sdk@^1.1.4": "@ray-js/panel-cloud@^1.2.0":
version "1.1.4" version "1.2.0"
resolved "https://registry.npmmirror.com/@ray-js/panel-base-sdk/-/panel-base-sdk-1.1.4.tgz" resolved "https://registry.npmmirror.com/@ray-js/panel-cloud/-/panel-cloud-1.2.0.tgz#74f27abc1c04bf2a3a585402c40fb5305eddc20d"
integrity sha512-W5yGVXX8BIrVMsQeXAIeklXR1j+0pkGd8d8ZMjHNQ1vg31SLrdJg0ZbASRrluTRd703d8Yn8r/EJ3Mt6KEDycg== integrity sha512-bG8x9F5wfBAfkC5BFS1iWb+s8FSC8U6hlpDmRdoAxa2TDl29ccE7jWtnUzMW6oBP/QeU00aBk7KIZ0WKDntqzQ==
dependencies: dependencies:
base64-browser "^1.0.1" "@ray-js/panel-shared" "workspace:^1.2.0"
"@ray-js/panel-sdk@^1.1.3", "@ray-js/panel-sdk@^1.1.4": "@ray-js/panel-sdk@^1.2.1":
version "1.1.4" version "1.2.1"
resolved "https://registry.npmmirror.com/@ray-js/panel-sdk/-/panel-sdk-1.1.4.tgz" resolved "https://registry.npmmirror.com/@ray-js/panel-sdk/-/panel-sdk-1.2.1.tgz#ee49a3b5419249b157ef16f60b101b2e4f4be5af"
integrity sha512-Zp4dAAT4ubvjZkpE9exqnyquLWRD69GXSJurBRlodXFhbCpbOqqleLdm0tUg57OznC2n4fUy6jUAh7BWKBTUBg== integrity sha512-Oi7CPqXdRESbp7by5tbGa1wbXaoScaELwx3hanaSrLj65wtTEXfYVaPe1R+YKpPnjTKwiVFRqE+KR+GSjhDSTw==
dependencies: dependencies:
"@ray-js/panel-base-sdk" "^1.1.4" "@ray-js/panel-cloud" "^1.2.0"
"@ray-js/panel-shared" "^1.2.0"
use-context-selector "^1.4.1"
"@ray-js/panel-shared@^1.2.0", "@ray-js/panel-shared@workspace:^1.2.0":
version "1.2.0"
resolved "https://registry.npmmirror.com/@ray-js/panel-shared/-/panel-shared-1.2.0.tgz#6bd4c2e48d72fe4c406ac46bdc14979dedc19437"
integrity sha512-nkpCfUkN2kISLZ3595K7HLf4sCmyD9ziE1PN1Ex8Kj8hJR+KW/VkCIkJyj04syLR7fsebBZjyL9LrBcAp6dpKg==
dependencies:
base64-browser "^1.0.1"
"@ray-js/ray@^0.6.13": "@ray-js/ray@^0.6.13":
version "0.6.15" version "0.6.15"
...@@ -2086,15 +2095,6 @@ ...@@ -2086,15 +2095,6 @@
dependencies: dependencies:
"@ray-core/runtime" "^0.0.x" "@ray-core/runtime" "^0.0.x"
"@ray-js/sdm-react@^1.0.6":
version "1.0.6"
resolved "https://registry.npmmirror.com/@ray-js/sdm-react/-/sdm-react-1.0.6.tgz"
integrity sha512-NedLnzCrKMBrQ5MICAjpdQy0fd688heAt9gkb2HXdXBJlQzEJc9bSU5u+hlsIjsjmLEsQviq3xGFRC+jiM+dPA==
dependencies:
"@ray-js/panel-sdk" "^1.1.4"
"@tuya-miniapp/sdm" "^1.0.5"
use-context-selector "^1.4.1"
"@ray-js/shared@^0.6.15": "@ray-js/shared@^0.6.15":
version "0.6.15" version "0.6.15"
resolved "https://registry.npmmirror.com/@ray-js/shared/-/shared-0.6.15.tgz" resolved "https://registry.npmmirror.com/@ray-js/shared/-/shared-0.6.15.tgz"
...@@ -2181,20 +2181,6 @@ ...@@ -2181,20 +2181,6 @@
resolved "https://registry.npmmirror.com/@tootallnate/once/-/once-1.1.2.tgz" resolved "https://registry.npmmirror.com/@tootallnate/once/-/once-1.1.2.tgz"
integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw== integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==
"@tuya-miniapp/sdm@^1.0.5":
version "1.0.5"
resolved "https://registry.npmmirror.com/@tuya-miniapp/sdm/-/sdm-1.0.5.tgz"
integrity sha512-RYzGLG0LxUnOfQSOzUtzjaF3AdlFgDQ3SJN8I4lMUwJgQwKA54M/jIzDMYlUH7fiQc8jCPlIkMsqzI8B3IbgCQ==
dependencies:
"@ray-js/panel-sdk" "^1.1.4"
"@tuya-miniapp/sdm@^1.1.0-beta.0":
version "1.1.0-beta.0"
resolved "https://registry.npmmirror.com/@tuya-miniapp/sdm/-/sdm-1.1.0-beta.0.tgz"
integrity sha512-gHlO5RidaCTXx3AidxCJyrY6FuNgV70eAwpMYmqfB6qbf/TOe2YPaOQVIyowjkrfYD9/jzC5v2Da7wceHlhM9w==
dependencies:
"@ray-js/panel-sdk" "^1.1.3"
"@types/babel__core@^7.0.0", "@types/babel__core@^7.1.7": "@types/babel__core@^7.0.0", "@types/babel__core@^7.1.7":
version "7.1.19" version "7.1.19"
resolved "https://registry.npmmirror.com/@types/babel__core/-/babel__core-7.1.19.tgz" resolved "https://registry.npmmirror.com/@types/babel__core/-/babel__core-7.1.19.tgz"
...@@ -3445,7 +3431,7 @@ balanced-match@^1.0.0: ...@@ -3445,7 +3431,7 @@ balanced-match@^1.0.0:
base64-browser@^1.0.1: base64-browser@^1.0.1:
version "1.0.1" version "1.0.1"
resolved "https://registry.npmmirror.com/base64-browser/-/base64-browser-1.0.1.tgz" resolved "https://registry.npmmirror.com/base64-browser/-/base64-browser-1.0.1.tgz#994adc093a997c362969108f25f7ab0a7d8759cd"
integrity sha512-vX2+bhz7EWV+HUHYAZARTfePNNIAAXLbVvLMjz32aG2zcqvlt2v5k28Jl36djJ98Te1dSjVt1VJSvZ585BJlbg== integrity sha512-vX2+bhz7EWV+HUHYAZARTfePNNIAAXLbVvLMjz32aG2zcqvlt2v5k28Jl36djJ98Te1dSjVt1VJSvZ585BJlbg==
base64-js@^1.3.1: base64-js@^1.3.1:
...@@ -11085,7 +11071,7 @@ url@^0.11.0: ...@@ -11085,7 +11071,7 @@ url@^0.11.0:
use-context-selector@^1.4.1: use-context-selector@^1.4.1:
version "1.4.1" version "1.4.1"
resolved "https://registry.npmmirror.com/use-context-selector/-/use-context-selector-1.4.1.tgz" resolved "https://registry.npmmirror.com/use-context-selector/-/use-context-selector-1.4.1.tgz#eb96279965846b72915d7f899b8e6ef1d768b0ae"
integrity sha512-Io2ArvcRO+6MWIhkdfMFt+WKQX+Vb++W8DS2l03z/Vw/rz3BclKpM0ynr4LYGyU85Eke+Yx5oIhTY++QR0ZDoA== integrity sha512-Io2ArvcRO+6MWIhkdfMFt+WKQX+Vb++W8DS2l03z/Vw/rz3BclKpM0ynr4LYGyU85Eke+Yx5oIhTY++QR0ZDoA==
use-latest-callback@^0.1.5: use-latest-callback@^0.1.5:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment