123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- //表达式的选项值域选择器
- (function () {
- //备选的四个条件
- var ConditionEnum = {
- Equal: 0,
- NotEqual: 1,
- Includes: 2,
- NotIncludes: 3,
- };
- //当前选中的条件
- var _selectedCondition = 0;
- //对应的外部表达式环境属性ID
- var propertyId;
- //外部传入的当前设置
- var _curSetting;
- $(function () {
- //条件被选择时
- $(document).on("change", "input[name='condition']", function () {
- _selectedCondition = parseInt($(this).val());
- if (_selectedCondition < 2) {
- $('input[type="checkbox"][name="option"]:checked').each(function (index) {
- if (index > 0) {
- $(this).prop('checked', false);
- }
- });
- }
- });
- //选项被改变的时候
- $(document).on("change", "input[name='option']", function () {
- if (_selectedCondition < 2) {
- clearAll();
- $(this).prop("checked", true);
- if (_curSetting.showMode == "选项值域选择") $("#name").val(this.nextElementSibling.innerText)
- }
- });
- $("#search_text").on("keydown", function (e) {
- if (e.keyCode == 13) {
- $("#search_btn").click();
- }
- });
- $("input[name='option_type']").on("click", function () {
- let optionType = $(this).val();
- //动态选项
- if (optionType == "1") {
- $("#search_info").show();
- $('#clear_options').hide();
- $("#search_result")[0].innerText = "已选内容:" + (_curSetting.items?.join(",") ?? "无");
- $(".options_selector").empty();
- $("#search_text").focus();
- //根据输入内容查询后加载选项数据
- } else {
- //静态选项
- $("#search_info").hide();
- $('#clear_options').show();
- let optionData = _curSetting.options(_curSetting.propertyId);
- LoadOptionData(optionData, _curSetting.items);
- }
- });
- $("#search_btn").on("click", function () {
- let searchKey = $("#search_text").val();
- if (searchKey == null || searchKey == "") {
- layer.msg('请输入搜索关键字', { time: 1000 });
- $("#search_text").focus();
- return;
- }
- let optionData = _curSetting.options(_curSetting.propertyId, searchKey);
- LoadOptionData(optionData, _curSetting.items);
- });
- $("#clear_options").on("click", function () {
- $("input[name='option']").prop("checked", false);
- });
- });
- /**
- * 清楚所有选项内容
- */
- function clearAll() {
- $("input[name='option']").prop("checked", false);
- }
- /**
- 获取表达式代码
- */
- GetEnumSetting = function () {
- let name = $("#name").val();
- if (name == null || name == "") {
- layer.msg('名称不能为空', { time: 1000 });
- return null;
- }
- //这里不取id,因为解析执行是按照文本来的,取下一个元素的文本
- let selItems = $("input[name='option']:checked").map(function (e) {
- let ret = this.nextElementSibling.innerText;
- //如果是返回名称,则要加上引号,以便存储为字符型
- if (_curSetting.selItemMode == "value") ret = this.value;
- return ret;
- }).get();
- let result = {
- name: name,
- propertyId: _curSetting.propertyId,
- selectedCondition: _selectedCondition,
- items: selItems
- }
- return result;
- }
- /**
- * 初始化
- */
- Init = function (curSetting, allSettings) {
- _curSetting = curSetting;
- _selectedCondition = curSetting.selectedCondition ?? 0;
- if (curSetting != null) {
- $("#name").val(curSetting.name);
- //设置选项对比条件
- if (curSetting.selectedCondition) {
- $(`input[name='condition'][value=${curSetting.selectedCondition}]`).prop('checked', true);
- }
- //设置选项
- if (curSetting.options) {
- if (typeof curSetting.options !== "function") {
- $("#option_type").hide();
- LoadOptionData(curSetting.options, curSetting.items);
- }
- }
- }
- if (_curSetting.showMode == "选项值域选择") {
- $("fieldset[name='symbol']")[0].style.display = "none";
- $(".condition_selector")[0].style.display = "none";
- }
- }
- //加载选项数据
- function LoadOptionData(optionList, curSelItems) {
- if (optionList.length > 10000) {
- layer.msg('选项数据过多,只显示了前1万行,如需查找需要的选项,请输入关键字查找', { time: 5000 });
- optionList = optionList.slice(0, 10000);
- }
- $(".options_selector").empty();
- for (var option of optionList) {
- $(".options_selector").append($(`<label><input type="checkbox" name="option"
- value="${option.value}" ${curSelItems?.includes(_curSetting.selItemMode == "value" ? option.value : option.display) ? 'checked' : ''}/>
- <span>${option.display}</span></label>`));
- }
- //先改了运算符再执行选项加载
- if (_selectedCondition < 2) {
- $('input[type="checkbox"][name="option"]:checked').each(function (index) {
- if (index > 0) {
- $(this).prop('checked', false);
- }
- });
- }
- }
- })();
|