123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- "use strict";
- const common_vendor = require("../../../../common/vendor.js");
- const _sfc_main = {
- name: "uni-easyinput",
- emits: ["click", "iconClick", "update:modelValue", "input", "focus", "blur", "confirm"],
- model: {
- prop: "modelValue",
- event: "update:modelValue"
- },
- props: {
- name: String,
- value: [Number, String],
- modelValue: [Number, String],
- type: {
- type: String,
- default: "text"
- },
- clearable: {
- type: Boolean,
- default: true
- },
- autoHeight: {
- type: Boolean,
- default: false
- },
- placeholder: String,
- placeholderStyle: String,
- focus: {
- type: Boolean,
- default: false
- },
- disabled: {
- type: Boolean,
- default: false
- },
- maxlength: {
- type: [Number, String],
- default: 140
- },
- confirmType: {
- type: String,
- default: "done"
- },
- clearSize: {
- type: [Number, String],
- default: 15
- },
- inputBorder: {
- type: Boolean,
- default: true
- },
- prefixIcon: {
- type: String,
- default: ""
- },
- suffixIcon: {
- type: String,
- default: ""
- },
- trim: {
- type: [Boolean, String],
- default: true
- },
- passwordIcon: {
- type: Boolean,
- default: true
- },
- styles: {
- type: Object,
- default() {
- return {
- color: "#333",
- disableColor: "#F7F6F6",
- borderColor: "#e5e5e5"
- };
- }
- },
- errorMessage: {
- type: [String, Boolean],
- default: ""
- },
- paddingLeft: {
- type: [Number, String],
- default: 0
- }
- },
- data() {
- return {
- focused: false,
- errMsg: "",
- val: "",
- showMsg: "",
- border: false,
- isFirstBorder: false,
- showClearIcon: false,
- showPassword: false
- };
- },
- computed: {
- msg() {
- return this.errorMessage || this.errMsg;
- },
- // 因为uniapp的input组件的maxlength组件必须要数值,这里转为数值,用户可以传入字符串数值
- inputMaxlength() {
- return Number(this.maxlength);
- }
- },
- watch: {
- value(newVal) {
- if (this.errMsg)
- this.errMsg = "";
- this.val = newVal;
- if (this.form && this.formItem && !this.is_reset) {
- this.is_reset = false;
- this.formItem.setValue(newVal);
- }
- },
- modelValue(newVal) {
- if (this.errMsg)
- this.errMsg = "";
- this.val = newVal;
- if (this.form && this.formItem && !this.is_reset) {
- this.is_reset = false;
- this.formItem.setValue(newVal);
- }
- },
- focus(newVal) {
- this.$nextTick(() => {
- this.focused = this.focus;
- });
- }
- },
- created() {
- if (!this.value && this.value !== 0) {
- this.val = this.modelValue;
- }
- if (!this.modelValue && this.modelValue !== 0) {
- this.val = this.value;
- }
- this.form = this.getForm("uniForms");
- this.formItem = this.getForm("uniFormsItem");
- if (this.form && this.formItem) {
- if (this.formItem.name) {
- if (!this.is_reset) {
- this.is_reset = false;
- this.formItem.setValue(this.val);
- }
- this.rename = this.formItem.name;
- this.form.inputChildrens.push(this);
- }
- }
- },
- mounted() {
- this.$nextTick(() => {
- this.focused = this.focus;
- });
- },
- methods: {
- /**
- * 初始化变量值
- */
- init() {
- },
- onClickIcon(type) {
- this.$emit("iconClick", type);
- },
- /**
- * 获取父元素实例
- */
- getForm(name = "uniForms") {
- let parent = this.$parent;
- let parentName = parent.$options.name;
- while (parentName !== name) {
- parent = parent.$parent;
- if (!parent)
- return false;
- parentName = parent.$options.name;
- }
- return parent;
- },
- onEyes() {
- this.showPassword = !this.showPassword;
- },
- onInput(event) {
- let value = event.detail.value;
- if (this.trim) {
- if (typeof this.trim === "boolean" && this.trim) {
- value = this.trimStr(value);
- }
- if (typeof this.trim === "string") {
- value = this.trimStr(value, this.trim);
- }
- }
- if (this.errMsg)
- this.errMsg = "";
- this.val = value;
- this.$emit("input", value);
- this.$emit("update:modelValue", value);
- },
- onFocus(event) {
- this.$emit("focus", event);
- },
- onBlur(event) {
- event.detail.value;
- this.$emit("blur", event);
- },
- onConfirm(e) {
- this.$emit("confirm", e.detail.value);
- },
- onClear(event) {
- this.val = "";
- this.$emit("input", "");
- this.$emit("update:modelValue", "");
- },
- fieldClick() {
- this.$emit("click");
- },
- trimStr(str, pos = "both") {
- if (pos === "both") {
- return str.trim();
- } else if (pos === "left") {
- return str.trimLeft();
- } else if (pos === "right") {
- return str.trimRight();
- } else if (pos === "start") {
- return str.trimStart();
- } else if (pos === "end") {
- return str.trimEnd();
- } else if (pos === "all") {
- return str.replace(/\s+/g, "");
- } else if (pos === "none") {
- return str;
- }
- return str;
- }
- }
- };
- if (!Array) {
- const _easycom_uni_icons2 = common_vendor.resolveComponent("uni-icons");
- _easycom_uni_icons2();
- }
- const _easycom_uni_icons = () => "../../../uni-icons/components/uni-icons/uni-icons.js";
- if (!Math) {
- _easycom_uni_icons();
- }
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
- return common_vendor.e({
- a: $props.prefixIcon
- }, $props.prefixIcon ? {
- b: common_vendor.o(($event) => $options.onClickIcon("prefix")),
- c: common_vendor.p({
- type: $props.prefixIcon,
- color: "#c0c4cc"
- })
- } : {}, {
- d: $props.type === "textarea"
- }, $props.type === "textarea" ? {
- e: $props.inputBorder ? 1 : "",
- f: $props.name,
- g: $data.val,
- h: $props.placeholder,
- i: $props.placeholderStyle,
- j: $props.disabled,
- k: $options.inputMaxlength,
- l: $data.focused,
- m: $props.autoHeight,
- n: common_vendor.o((...args) => $options.onInput && $options.onInput(...args)),
- o: common_vendor.o((...args) => $options.onBlur && $options.onBlur(...args)),
- p: common_vendor.o((...args) => $options.onFocus && $options.onFocus(...args)),
- q: common_vendor.o((...args) => $options.onConfirm && $options.onConfirm(...args))
- } : {
- r: $props.type === "password" ? "text" : $props.type,
- s: $props.type === "password" || $props.clearable || $props.prefixIcon ? "" : "10px",
- t: $props.paddingLeft + "px",
- v: $props.name,
- w: $data.val,
- x: !$data.showPassword && $props.type === "password",
- y: $props.placeholder,
- z: $props.placeholderStyle,
- A: $props.disabled,
- B: $options.inputMaxlength,
- C: $data.focused,
- D: $props.confirmType,
- E: common_vendor.o((...args) => $options.onFocus && $options.onFocus(...args)),
- F: common_vendor.o((...args) => $options.onBlur && $options.onBlur(...args)),
- G: common_vendor.o((...args) => $options.onInput && $options.onInput(...args)),
- H: common_vendor.o((...args) => $options.onInput && $options.onInput(...args)),
- I: common_vendor.o((...args) => $options.onConfirm && $options.onConfirm(...args))
- }, {
- J: $props.type === "password" && $props.passwordIcon
- }, $props.type === "password" && $props.passwordIcon ? common_vendor.e({
- K: $data.val
- }, $data.val ? {
- L: $props.type === "textarea" ? 1 : "",
- M: common_vendor.o($options.onEyes),
- N: common_vendor.p({
- type: $data.showPassword ? "eye-slash-filled" : "eye-filled",
- size: 18,
- color: "#c0c4cc"
- })
- } : {}) : $props.suffixIcon ? common_vendor.e({
- P: $props.suffixIcon
- }, $props.suffixIcon ? {
- Q: common_vendor.o(($event) => $options.onClickIcon("suffix")),
- R: common_vendor.p({
- type: $props.suffixIcon,
- color: "#c0c4cc"
- })
- } : {}) : common_vendor.e({
- S: $props.clearable && $data.val && !$props.disabled
- }, $props.clearable && $data.val && !$props.disabled ? {
- T: $props.type === "textarea" ? 1 : "",
- U: common_vendor.o($options.onClear),
- V: common_vendor.p({
- type: "clear",
- size: $props.clearSize,
- color: "#c0c4cc"
- })
- } : {}), {
- O: $props.suffixIcon,
- W: $props.inputBorder ? 1 : "",
- X: $props.inputBorder && $options.msg ? 1 : "",
- Y: $props.type === "textarea" ? 1 : "",
- Z: $props.disabled ? 1 : "",
- aa: $props.inputBorder && $options.msg ? "#dd524d" : $props.styles.borderColor,
- ab: $props.disabled ? $props.styles.disableColor : "",
- ac: $options.msg ? 1 : "",
- ad: $props.inputBorder && $options.msg ? "#e43d33" : $props.styles.color
- });
- }
- const Component = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["render", _sfc_render], ["__file", "/Users/RuHu.Xu/Desktop/mall-newfeifan-zx-app/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue"]]);
- wx.createComponent(Component);
|