vue3-calculator
Version:
A Vue 3 calculator component with scientific and standard modes
99 lines (89 loc) • 3.08 kB
TypeScript
import { ComponentOptionsMixin } from 'vue';
import { ComponentProvideOptions } from 'vue';
import { ComputedRef } from 'vue';
import { DefineComponent } from 'vue';
import { PublicProps } from 'vue';
import { Ref } from 'vue';
/**
* 计算器按键类型
*/
export declare type ButtonType = "number" | "operator" | "function" | "clear";
export declare const Calculator: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {
displayRef: HTMLDivElement;
}, HTMLDivElement>;
/**
* 计算器状态接口
*/
export declare interface CalculatorState {
display: string;
previousValue: string;
currentOperator: OperatorType;
waitingForNewValue: boolean;
history: string[];
memory: string;
isError: boolean;
errorMessage: string;
}
/**
* 默认导出,支持多种使用方式
*/
declare const _default: {
install: typeof install;
Calculator: DefineComponent< {}, {}, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {}, string, PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {
displayRef: HTMLDivElement;
}, HTMLDivElement>;
useCalculator: typeof useCalculator;
useCalculatorStore: typeof useCalculator;
};
export default _default;
/**
* Vue插件安装函数
* @param app Vue 应用实例
*/
export declare function install(app: any): void;
/**
* 操作符类型
*/
export declare type OperatorType = "+" | "-" | "*" | "/" | "=" | null;
/**
* 计算器 Hook
* 使用 Vue3 Composition API 实现状态管理,替代 Pinia
*/
declare function useCalculator(): {
display: Ref<string, string>;
previousValue: Ref<string, string>;
currentOperator: Ref<OperatorType, OperatorType>;
waitingForNewValue: Ref<boolean, boolean>;
history: Ref<string[], string[]>;
memory: Ref<string, string>;
isError: Ref<boolean, boolean>;
errorMessage: Ref<string, string>;
expression: Ref<string, string>;
displayText: ComputedRef<string>;
expressionText: ComputedRef<string>;
inputNumber: (num: string) => void;
inputDecimal: () => void;
inputOperator: (operator: OperatorType) => void;
calculate: () => void;
removeHistoryItem: (index: number) => void;
clearEntry: () => void;
clearAll: () => void;
backspace: () => void;
toggleSign: () => void;
percentage: () => void;
squareRoot: () => void;
square: () => void;
reciprocal: () => void;
memoryStore: () => void;
memoryRecall: () => void;
memoryClear: () => void;
memoryAdd: () => void;
memorySubtract: () => void;
formatNumber: (value: string) => string;
scientificFunction: (func: string) => void;
factorial: () => void;
};
export { useCalculator }
export { useCalculator as useCalculatorStore }
export declare const version = "1.0.0";
export { }