• activiti5.22代理人、候选人改造--前端


    本文借鉴断翅绝尘Activiti流程编辑器针对自定义用户角色表优化改造一文

    针对自定义的用户、角色表,对Activiti的在线流程设计器进行优化改造,使之能直接在图形界面上完成对节点办理人、候选人、候选组的配置,不需要先去查数据库中的用户ID、角色ID等信息再填入。
    先上一张实现效果图:

    1、页面改造

    修改上图中的页面,主要是修改页面布局,以及将输入框添加一些事件,代码如下:

    1. <div style="width:100%;height:100%;" class="modal" ng-controller="KisBpmAssignmentPopupCtrl">
    2. <div style="width:80%;height:100%;" class="modal-dialog">
    3. <div class="modal-content">
    4. <div class="modal-header">
    5. <button type="button" class="close" data-dismiss="modal"
    6. aria-hidden="true" ng-click="close()">&times;</button>
    7. <h2 translate>PROPERTY.ASSIGNMENT.TITLE</h2>
    8. </div>
    9. <div class="modal-body">
    10. <div class="row row-no-gutter">
    11. <div class="col-xs-4">
    12. <div class="row row-no-gutter">
    13. <div class="form-group">
    14. <label for="assigneeField">{{'PROPERTY.ASSIGNMENT.ASSIGNEE'
    15. | translate}}</label> <input type="text" id="assigneeField"
    16. class="form-control" ng-model="assignment.assignee"
    17. ng-click="selectAssignee()"
    18. placeholder="{{'PROPERTY.ASSIGNMENT.ASSIGNEE_PLACEHOLDER' | translate}}" />
    19. </div>
    20. </div>
    21. <div class="row row-no-gutter">
    22. <div class="form-group">
    23. <label for="userField">{{'PROPERTY.ASSIGNMENT.CANDIDATE_USERS'
    24. | translate}}</label>
    25. <div ng-repeat="candidateUser in assignment.candidateUsers">
    26. <input id="userField" class="form-control" type="text"
    27. ng-model="candidateUser.value"
    28. ng-click="selectCandidate()" /> <i
    29. class="glyphicon glyphicon-minus clickable-property"
    30. ng-click="removeCandidateUserValue($index)"></i> <i
    31. ng-if="$index == (assignment.candidateUsers.length - 1)"
    32. class="glyphicon glyphicon-plus clickable-property"
    33. ng-click="addCandidateUserValue($index)"></i>
    34. </div>
    35. </div>
    36. <div class="form-group">
    37. <label for="groupField">{{'PROPERTY.ASSIGNMENT.CANDIDATE_GROUPS'
    38. | translate}}</label>
    39. <div ng-repeat="candidateGroup in assignment.candidateGroups">
    40. <input id="groupField" class="form-control" type="text"
    41. ng-model="candidateGroup.value"
    42. ng-click="selectGroup()" />
    43. <i class="glyphicon glyphicon-minus clickable-property"
    44. ng-click="removeCandidateGroupValue($index)"></i>
    45. <i ng-if="$index == (assignment.candidateGroups.length - 1)"
    46. class="glyphicon glyphicon-plus clickable-property"
    47. ng-click="addCandidateGroupValue($index)"></i>
    48. </div>
    49. </div>
    50. </div>
    51. </div>
    52. <div class="col-xs-8">
    53. <span class="mb10">
    54. <strong>{{selectTitle}}</strong>
    55. <select class="pull-right" ng-change="change(selectedProject)"
    56. id="project" ng-if="projects.length>0" ng-model="selectedProject" ng-options="project.pkid as project.projectName for project in projects">
    57. </select>
    58. </span>
    59. <div style="min-height:350px;" class="default-grid ng-scope ngGrid ng1521010657341 unselectable" ng-grid="gridOptions"></div>
    60. </div>
    61. </div>
    62. </div>
    63. <div class="modal-footer">
    64. <!-- <button ng-click="close()" class="btn btn-primary" translate>ACTION.CANCEL</button>-->
    65. <button ng-click="save()" class="btn btn-primary" translate>ACTION.SAVE</button>
    66. </div>
    67. </div>
    68. </div>
    69. </div>

    2、js改造

    修改上述js文件,代码如下:

    1. /*
    2. * Activiti Modeler component part of the Activiti project
    3. * Copyright 2005-2014 Alfresco Software, Ltd. All rights reserved.
    4. *
    5. * This library is free software; you can redistribute it and/or
    6. * modify it under the terms of the GNU Lesser General Public
    7. * License as published by the Free Software Foundation; either
    8. * version 2.1 of the License, or (at your option) any later version.
    9. *
    10. * This library is distributed in the hope that it will be useful,
    11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    13. * Lesser General Public License for more details.
    14. * You should have received a copy of the GNU Lesser General Public
    15. * License along with this library; if not, write to the Free Software
    16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
    17. */
    18. /*
    19. * Assignment
    20. */
    21. var KisBpmAssignmentCtrl = [
    22. "$scope",
    23. "$modal",
    24. function ($scope, $modal) {
    25. // Config for the modal window
    26. var opts = {
    27. template:
    28. "editor-app/configuration/properties/assignment-popup.html?version=" +
    29. Date.now(),
    30. scope: $scope,
    31. };
    32. // Open the dialog
    33. $modal(opts);
    34. },
    35. ];
    36. var KisBpmAssignmentPopupCtrl = [
    37. "$scope",
    38. "$http",
    39. function ($scope, $http) {
    40. // Put json representing assignment on scope
    41. if (
    42. $scope.property.value !== undefined &&
    43. $scope.property.value !== null &&
    44. $scope.property.value.assignment !== undefined &&
    45. $scope.property.value.assignment !== null
    46. ) {
    47. $scope.assignment = $scope.property.value.assignment;
    48. } else {
    49. $scope.assignment = {};
    50. }
    51. if (
    52. $scope.assignment.candidateUsers == undefined ||
    53. $scope.assignment.candidateUsers.length == 0
    54. ) {
    55. $scope.assignment.candidateUsers = [{ value: "" }];
    56. }
    57. // Click handler for + button after enum value
    58. var userValueIndex = 1;
    59. $scope.addCandidateUserValue = function (index) {
    60. $scope.assignment.candidateUsers.splice(index + 1, 0, {
    61. value: "value " + userValueIndex++,
    62. });
    63. };
    64. // Click handler for - button after enum value
    65. $scope.removeCandidateUserValue = function (index) {
    66. $scope.assignment.candidateUsers.splice(index, 1);
    67. };
    68. if (
    69. $scope.assignment.candidateGroups == undefined ||
    70. $scope.assignment.candidateGroups.length == 0
    71. ) {
    72. $scope.assignment.candidateGroups = [{ value: "" }];
    73. }
    74. var groupValueIndex = 1;
    75. $scope.addCandidateGroupValue = function (index) {
    76. $scope.assignment.candidateGroups.splice(index + 1, 0, {
    77. value: "value " + groupValueIndex++,
    78. });
    79. };
    80. // Click handler for - button after enum value
    81. $scope.removeCandidateGroupValue = function (index) {
    82. $scope.assignment.candidateGroups.splice(index, 1);
    83. };
    84. $scope.save = function () {
    85. $scope.property.value = {};
    86. handleAssignmentInput($scope);
    87. $scope.property.value.assignment = $scope.assignment;
    88. $scope.updatePropertyInModel($scope.property);
    89. $scope.close();
    90. };
    91. // Close button handler
    92. $scope.close = function () {
    93. handleAssignmentInput($scope);
    94. $scope.property.mode = "read";
    95. $scope.$hide();
    96. };
    97. var handleAssignmentInput = function ($scope) {
    98. if ($scope.assignment.candidateUsers) {
    99. var emptyUsers = true;
    100. var toRemoveIndexes = [];
    101. for (var i = 0; i < $scope.assignment.candidateUsers.length; i++) {
    102. if ($scope.assignment.candidateUsers[i].value != "") {
    103. emptyUsers = false;
    104. } else {
    105. toRemoveIndexes[toRemoveIndexes.length] = i;
    106. }
    107. }
    108. for (var i = 0; i < toRemoveIndexes.length; i++) {
    109. $scope.assignment.candidateUsers.splice(toRemoveIndexes[i], 1);
    110. }
    111. if (emptyUsers) {
    112. $scope.assignment.candidateUsers = undefined;
    113. }
    114. }
    115. if ($scope.assignment.candidateGroups) {
    116. var emptyGroups = true;
    117. var toRemoveIndexes = [];
    118. for (var i = 0; i < $scope.assignment.candidateGroups.length; i++) {
    119. if ($scope.assignment.candidateGroups[i].value != "") {
    120. emptyGroups = false;
    121. } else {
    122. toRemoveIndexes[toRemoveIndexes.length] = i;
    123. }
    124. }
    125. for (var i = 0; i < toRemoveIndexes.length; i++) {
    126. $scope.assignment.candidateGroups.splice(toRemoveIndexes[i], 1);
    127. }
    128. if (emptyGroups) {
    129. $scope.assignment.candidateGroups = undefined;
    130. }
    131. }
    132. };
    133. /*---------------------流程设计器扩展用户与用户组--------------------*/
    134. //参数初始化
    135. $scope.gridData = [];//表格数据
    136. $scope.gridDataName = 'gridData';
    137. $scope.selectTitle = '选择代理人';
    138. $scope.columnData = [];//表格列数据
    139. $scope.columnDataName = 'columnData';
    140. $scope.selectType = 0;//0-代理人,1-候选人,2-候选组
    141. $scope.totalServerItems = 0;//表格总条数
    142. //分页初始化
    143. $scope.pagingOptions = {
    144. pageSizes: [10, 20, 30],//page 行数可选值
    145. pageSize: 10, //每页行数
    146. currentPage: 1, //当前显示页数
    147. };
    148. //Grid 筛选
    149. $scope.projects = [];
    150. $scope.selectedProject = -1;
    151. //异步请求项目列表数据
    152. $scope.getProjectDataAsync = function(){
    153. $http({
    154. method: 'POST',
    155. url: ACTIVITI.CONFIG.contextRoot+'/model/getProjectList'
    156. }).then(function successCallback(response) {
    157. $scope.projects = response.data;
    158. if($scope.projects.length > 0){
    159. $scope.selectedProject = $scope.projects[0].pkid;
    160. }
    161. $scope.dataWatch();
    162. }, function errorCallback(response) {
    163. // 请求失败执行代码
    164. console.log("项目列表请求失败!");
    165. });
    166. }
    167. $scope.getProjectDataAsync();
    168. //数据监视
    169. $scope.dataWatch = function (){
    170. //分页数据监视
    171. $scope.$watch('pagingOptions', function (newValue, oldValue) {
    172. $scope.getPagedDataAsync($scope.pagingOptions.currentPage, $scope.pagingOptions.pageSize, $scope.selectedProject);
    173. },true);
    174. //当切换类型时,初始化当前页
    175. $scope.$watch('selectType', function (newValue, oldValue) {
    176. if(newValue != oldValue){
    177. $scope.pagingOptions.currentPage = 1;
    178. $scope.getPagedDataAsync($scope.pagingOptions.currentPage, $scope.pagingOptions.pageSize, $scope.selectedProject);
    179. }
    180. },true);
    181. //切换平台
    182. $scope.change = function(x){
    183. $scope.selectedProject = x;
    184. $scope.getPagedDataAsync($scope.pagingOptions.currentPage, $scope.pagingOptions.pageSize, $scope.selectedProject);
    185. };
    186. };
    187. //异步请求表格数据
    188. $scope.getPagedDataAsync = function(pageNum, pageSize, projectId){
    189. var url;
    190. if($scope.selectType == 2){
    191. url = '/model/getGroupList';
    192. $scope.columnData = $scope.groupColumns;
    193. }else{
    194. url = '/model/getUserList';
    195. $scope.columnData = $scope.userColumns;
    196. }
    197. $http({
    198. method: 'POST',
    199. url: ACTIVITI.CONFIG.contextRoot+url,
    200. params:{
    201. 'pageNum': pageNum,
    202. 'pageSize': pageSize,
    203. 'projectId': projectId
    204. },
    205. }).then(function successCallback(response) {
    206. $scope.gridData = response.data.rows;
    207. $scope.totalServerItems = response.data.total;
    208. }, function errorCallback(response) {
    209. // 请求失败执行代码
    210. $scope.gridData = [];
    211. $scope.totalServerItems = 0;
    212. });
    213. }
    214. //表格属性配置
    215. $scope.gridOptions = {
    216. data: $scope.gridDataName,
    217. multiSelect: false,//不可多选
    218. enablePaging: true,
    219. pagingOptions: $scope.pagingOptions,
    220. totalServerItems: 'totalServerItems',
    221. i18n:'zh-cn',
    222. showFooter: true,
    223. showSelectionCheckbox: false,
    224. columnDefs : $scope.columnDataName,
    225. beforeSelectionChange: function (event) {
    226. var data = event.entity.pkid;
    227. if($scope.selectType == 0){//选代理人
    228. event.entity.checked = !event.selected;
    229. $scope.assignment.assignee = data;
    230. }else if($scope.selectType == 1){//候选人
    231. var obj = {value: data};
    232. if(!array_contain($scope.assignment.candidateUsers, obj.value)){
    233. $scope.assignment.candidateUsers.push(obj);
    234. }
    235. }else if($scope.selectType == 2){//候选组
    236. var obj = {value: $scope.getGroupData(event.entity)};
    237. if(!array_contain($scope.assignment.candidateGroups, obj.value)){
    238. $scope.assignment.candidateGroups.push(obj);
    239. }
    240. }
    241. return true;
    242. }
    243. };
    244. $scope.getGroupData = function(data){
    245. var prefix = ['${projectId}_','${bankEnterpriseId}_','${coreEnterpriseId}_','${chainEnterpriseId}_'];
    246. var result = prefix[data.enterpriseType] + data.roleCode;
    247. return result;
    248. };
    249. //选择用户时表头
    250. $scope.userColumns = [
    251. {
    252. field : 'pkid',
    253. type:'number',
    254. displayName : '用户Id',
    255. minWidth: 100,
    256. width : '18%'
    257. },
    258. {
    259. field : 'nickName',
    260. displayName : '昵称',
    261. minWidth: 100,
    262. width : '25%'
    263. },
    264. {
    265. field : 'loginName',
    266. displayName : '登录名',
    267. minWidth: 100,
    268. width : '25%'
    269. },
    270. {
    271. field : 'realName',
    272. displayName : '姓名',
    273. minWidth: 100,
    274. width : '25%'
    275. }
    276. ];
    277. $scope.displayText = function(enterpriseType){
    278. var tmp = '';
    279. switch(enterpriseType){
    280. case 0:
    281. tmp = '运营';
    282. break;
    283. case 1:
    284. tmp = '银行';
    285. break;
    286. case 2:
    287. tmp = '核心';
    288. break;
    289. case 3:
    290. tmp = '链属';
    291. break;
    292. default:
    293. tmp = 'N/A';
    294. break;
    295. }
    296. return tmp;
    297. }
    298. //选择用户组时表头
    299. $scope.groupColumns = [
    300. {
    301. field : 'pkid',
    302. type:'number',
    303. displayName : '角色Id',
    304. minWidth: 100,
    305. width : '16%'
    306. },
    307. {
    308. field : 'roleCode',
    309. displayName : '角色code',
    310. minWidth: 100,
    311. width : '16%'
    312. },
    313. {
    314. field : 'name',
    315. displayName : '角色名称',
    316. minWidth: 100,
    317. width : '25%'
    318. },
    319. {
    320. field : 'type',
    321. type:'number',
    322. displayName : '角色类型',
    323. minWidth: 100,
    324. width : '18%',
    325. cellTemplate : '{{row.entity.type==1?"公有":"私有"}}'
    326. },
    327. {
    328. field : 'enterpriseType',
    329. displayName : '业务类型',
    330. minWidth: 100,
    331. width : '18%'
    332. ,cellTemplate : '{{displayText(row.entity.enterpriseType);}}'
    333. }
    334. ];
    335. //代理人(审批人)
    336. $scope.selectAssignee = function () {
    337. $scope.selectType = 0;
    338. $scope.selectTitle = '选择代理人';
    339. };
    340. //候选人
    341. $scope.selectCandidate = function () {
    342. $scope.selectType = 1;
    343. $scope.selectTitle = '选择候选人';
    344. };
    345. //候选组
    346. $scope.selectGroup = function () {
    347. $scope.selectType = 2;
    348. $scope.selectTitle = '选择候选组';
    349. };
    350. }];
    351. //声明----如果有此 contains 直接用最好
    352. function array_contain(array, obj){
    353. for (var i = 0; i < array.length; i++){
    354. if (array[i].value == obj)//如果要求数据类型也一致,这里可使用恒等号===
    355. return true;
    356. }
    357. return false;
    358. }

    其中,查询用户和角色列表的接口需要后端接口提供:

    1. //异步请求表格数据
    2. $scope.getPagedDataAsync = function(pageNum, pageSize, projectId){
    3. var url;
    4. if($scope.selectType == 2){
    5. url = '/model/getGroupList';
    6. $scope.columnData = $scope.groupColumns;
    7. }else{
    8. url = '/model/getUserList';
    9. $scope.columnData = $scope.userColumns;
    10. }
    11. $http({
    12. method: 'POST',
    13. url: ACTIVITI.CONFIG.contextRoot+url,
    14. params:{
    15. 'pageNum': pageNum,
    16. 'pageSize': pageSize,
    17. 'projectId': projectId
    18. },
    19. }).then(function successCallback(response) {
    20. $scope.gridData = response.data.rows;
    21. $scope.totalServerItems = response.data.total;
    22. }, function errorCallback(response) {
    23. // 请求失败执行代码
    24. $scope.gridData = [];
    25. $scope.totalServerItems = 0;
    26. });
    27. }

    本文实现了先选项目,然后再加载用户和角色列表,因此代码中多出了这一部分,读者可根据需要决定是否去除:

    1. //异步请求项目列表数据
    2. $scope.getProjectDataAsync = function(){
    3. $http({
    4. method: 'POST',
    5. url: ACTIVITI.CONFIG.contextRoot+'/model/getProjectList'
    6. }).then(function successCallback(response) {
    7. $scope.projects = response.data;
    8. if($scope.projects.length > 0){
    9. $scope.selectedProject = $scope.projects[0].pkid;
    10. }
    11. $scope.dataWatch();
    12. }, function errorCallback(response) {
    13. // 请求失败执行代码
    14. console.log("项目列表请求失败!");
    15. });
    16. }

    最终实现的效果是:
    1)点击办理人输入框,右侧立即加载用户列表,支持分页,点击右侧某个用户,该用户的ID自动填入办理人输入框;
    2)点击候选人输入框,右侧立即加载用户列表,支持分页,点击右侧某个用户,该用户的ID自动填入候选人输入框,可多次点击用户添加多个候选人;
    3)点击候选组输入框,右侧加载角色列表,支持分页,点击某个角色,该角色编号自动填入候选组输入框,可多次点击角色添加多个候选组;


    3、token获取对接后台

    集成模型设计,例如:

    1. <template>
    2. <div style="position:relative;height: 100%;">
    3. <iframe
    4. id="iframe"
    5. :src="modelerUrl"
    6. frameborder="0"
    7. width="100%"
    8. height="720px"
    9. scrolling="auto"
    10. />
    11. <Spin v-if="modelerLoading" fix size="large" />
    12. </div>
    13. </template>
    14. <script>
    15. //获取token的方式可能不一样,视情况而定
    16. import { getToken } from '@/utils/auth'
    17. export default {
    18. name: 'ModelDefine',
    19. components: {},
    20. data() {
    21. return {
    22. modelerLoading: true,
    23. modelerUrl: '/static/modeler.html?modelId=' + this.$route.query.id + '&time=' + new Date().getTime()
    24. }
    25. },
    26. computed: {
    27. token() {
    28. return 'Bearer ' + getToken()
    29. }
    30. },
    31. created() {},
    32. mounted() {
    33. window.getMyVue = this
    34. },
    35. methods: {}
    36. }
    37. </script>
    38. <style lang="scss" scoped>
    39. .iframe {
    40. width: 100%;
    41. height: calc(100vh - 154px);
    42. }
    43. </style>

    打开static/modeler.html添加一下代码

    1. <script>
    2. (
    3. function (open) {
    4. XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {
    5. open.call(this, method, url, async, user, pass); //this指XMLHttpRequest
    6. this.setRequestHeader("Authorization", window.parent.getMyVue.token); //mounted时传入的token
    7. };
    8. }
    9. )(XMLHttpRequest.prototype.open);
    10. </script>


    修改接口配置static/editor-app/app-cfg.js

     

    完成上述几步,前端集成基本结束。

  • 相关阅读:
    揭开MyBatis的神秘面纱:掌握动态代理在底层实现中的精髓
    [《南国雪下》闲笔记事集]2010年12月15日 记雪
    硅芯思见:【145】问芯吾跬(IC设计验证常见问题汇总三)
    订水商城实战教程10-宫格导航
    振南技术干货集:C语言的一些“骚操作”及其深层理解(3)
    (六)admin-boot项目之全局处理预防xss攻击
    Shopify独立站如何做好邮件营销
    所有 WCF 超时说明
    JVM运行时数据区域详解
    JS逆向——建筑市场监管公共服务平台
  • 原文地址:https://blog.csdn.net/fanghe1995/article/details/127673845