@fe6/water-pro
Version:
An enterprise-class UI design language and Vue-based implementation
88 lines (71 loc) • 3.05 kB
JavaScript
import _regeneratorRuntime from "@babel/runtime/regenerator";
/** @format */
import { __awaiter } from "tslib";
import { unref, nextTick, watchEffect } from 'vue';
export function useAutoFocus(_ref) {
var getSchema = _ref.getSchema,
autoFocusFirstItem = _ref.autoFocusFirstItem,
formElRef = _ref.formElRef,
isInitedDefault = _ref.isInitedDefault;
return __awaiter(this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
var _this = this;
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
watchEffect(function () {
return __awaiter(_this, void 0, void 0, /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
var _a, schemas, formEl, el, firstItem, inputEl;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
if (!(unref(isInitedDefault) || !unref(autoFocusFirstItem))) {
_context.next = 2;
break;
}
return _context.abrupt("return");
case 2:
_context.next = 4;
return nextTick();
case 4:
schemas = unref(getSchema);
formEl = unref(formElRef);
el = (_a = formEl) === null || _a === void 0 ? void 0 : _a.$el;
if (!(!formEl || !el || !schemas || schemas.length === 0)) {
_context.next = 9;
break;
}
return _context.abrupt("return");
case 9:
firstItem = schemas[0]; // Only open when the first form item is input type
if (firstItem.component.includes('Input')) {
_context.next = 12;
break;
}
return _context.abrupt("return");
case 12:
inputEl = el.querySelector('.ant-row:first-child input');
if (inputEl) {
_context.next = 15;
break;
}
return _context.abrupt("return");
case 15:
inputEl === null || inputEl === void 0 ? void 0 : inputEl.focus();
case 16:
case "end":
return _context.stop();
}
}
}, _callee);
}));
});
case 1:
case "end":
return _context2.stop();
}
}
}, _callee2);
}));
}